/* CHATD: A chat server using the SDL example network library Copyright (C) 1997-2004 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Sam Lantinga slouken@libsdl.org */ /* Note that this isn't necessarily the way to run a chat system. This is designed to excercise the network code more than be really functional. */ #include #include #include #include "SDL.h" #include "SDL_net.h" #include "chat.h" /* This is really easy. All we do is monitor connections */ static TCPsocket servsock = NULL; static SDLNet_SocketSet socketset = NULL; static struct { int active; TCPsocket sock; IPaddress peer; Uint8 name[256+1]; } people[CHAT_MAXPEOPLE]; void HandleServer(void) { TCPsocket newsock; int which; unsigned char data; newsock = SDLNet_TCP_Accept(servsock); if ( newsock == NULL ) { return; } /* Look for unconnected person slot */ for ( which=0; which