remove unneeded files

This commit is contained in:
dborth 2009-05-08 07:41:25 +00:00
parent 806019e2d4
commit e9b7ee50bf
11 changed files with 0 additions and 11269 deletions

View file

@ -1,67 +0,0 @@
# Makefile.am for the SDL sample image loading library and viewer
lib_LTLIBRARIES = libSDL_net.la
libSDL_netincludedir = $(includedir)/SDL
libSDL_netinclude_HEADERS = \
SDL_net.h
libSDL_net_la_SOURCES = \
SDLnet.c \
SDLnetTCP.c \
SDLnetUDP.c \
SDLnetselect.c \
SDLnetsys.h
EXTRA_DIST = \
CHANGES \
version.rc \
VisualC.zip \
Xcode.tar.gz \
MPWmake.sea.bin \
Watcom-OS2.zip \
quit.bmp \
scroll_dn.bmp \
scroll_up.bmp \
SDL_net.spec \
SDL_net.spec.in \
gcc-fat.sh \
autogen.sh
if USE_VERSION_RC
libSDL_net_la_LDFLAGS = \
-no-undefined \
-release $(LT_RELEASE) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -Wl,version.o
libSDL_net_la_LIBADD = @INETLIB@
libSDL_net_la_DEPENDENCIES = version.o
else
libSDL_net_la_LDFLAGS = \
-no-undefined \
-release $(LT_RELEASE) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
libSDL_net_la_LIBADD = @INETLIB@
endif
%.o : %.rc
$(WINDRES) $< $@
if HAVE_GUI_LIB
EXAMPLES = chat chatd
else
EXAMPLES =
endif
noinst_PROGRAMS = $(EXAMPLES)
chat_SOURCES = chat.cpp chat.h
chat_LDADD = libSDL_net.la -lGUI
chatd_SOURCES = chatd.c
chatd_LDADD = libSDL_net.la
# Rule to build tar-gzipped distribution package
$(PACKAGE)-$(VERSION).tar.gz: distcheck
# Rule to build RPM distribution package
rpm: $(PACKAGE)-$(VERSION).tar.gz
rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz

View file

@ -1,96 +0,0 @@
<QPG:Generation>
<QPG:Options>
<QPG:User unattended="yes" verbosity="0" listfiles="yes"/>
<QPG:Defaults type="qnx_package"/>
<QPG:Source></QPG:Source>
<QPG:Release date="today" number="+"/>
<QPG:Build></QPG:Build>
<QPG:FileSorting strip="yes"/>
<QPG:Package targets="standart"/>
<QPG:Repository generate="yes"/>
<QPG:FinalDir></QPG:FinalDir>
<QPG:Cleanup></QPG:Cleanup>
</QPG:Options>
<QPG:Responsible>
<QPG:Company>QNX.ORG.RU Community</QPG:Company>
<QPG:Department></QPG:Department>
<QPG:Group></QPG:Group>
<QPG:Team>QNX.ORG.RU Team</QPG:Team>
<QPG:Employee>Mike Gorchak</QPG:Employee>
<QPG:EmailAddress>mike@malva.ua</QPG:EmailAddress>
</QPG:Responsible>
<QPG:Values>
<QPG:Files>
<QPG:Add file="./COPYING" install="LicenseUrl/" handling="repdata"/>
<QPG:Add permissions="0755" file="./.libs/libSDL_net-1.2.so.0" install="/opt/lib/"/>
<QPG:Add filetype="symlink" file="libSDL_net.so" install="/opt/lib/" linkto="libSDL_net-1.2.so.0"/>
<QPG:Add filetype="symlink" file="libSDL_net-1.1.so.0" install="/opt/lib/" linkto="libSDL_net-1.2.so.0"/>
<QPG:Add filetype="symlink" file="libSDL_net-1.0.so.0" install="/opt/lib/" linkto="libSDL_net-1.2.so.0"/>
<QPG:Add permissions="0644" file="./.libs/libSDL_net.a" install="/opt/lib/"/>
<QPG:Add permissions="0644" file="./.libs/libSDL_net.lai" install="/opt/lib/libSDL_net.la"/>
<QPG:Add permissions="0644" file="./SDL_net.h" install="/opt/include/SDL/"/>
<QPG:Add permissions="0644" file="./CHANGES" install="/usr/doc/SDL12_net/"/>
<QPG:Add permissions="0644" file="./COPYING" install="/usr/doc/SDL12_net/"/>
<QPG:Add permissions="0644" file="./README" install="/usr/doc/SDL12_net/"/>
</QPG:Files>
<QPG:PackageFilter>
<QPM:PackageManifest>
<QPM:PackageDescription>
<QPM:PackageType>Library</QPM:PackageType>
<QPM:PackageName>SDL_net</QPM:PackageName>
<QPM:PackageReleaseNumber>1</QPM:PackageReleaseNumber>
<QPM:PackageRepository>http://qnx.org.ru/repository</QPM:PackageRepository>
<QPM:FileVersion>2.0</QPM:FileVersion>
</QPM:PackageDescription>
<QPM:ProductDescription>
<QPM:ProductName>SDL_net</QPM:ProductName>
<QPM:ProductIdentifier>SDL_net</QPM:ProductIdentifier>
<QPM:ProductEmail>slouken@libsdl.org</QPM:ProductEmail>
<QPM:VendorName>public</QPM:VendorName>
<QPM:VendorInstallName>public</QPM:VendorInstallName>
<QPM:VendorURL>http://www.libsdl.org</QPM:VendorURL>
<QPM:VendorEmbedURL/>
<QPM:VendorEmail>slouken@libsdl.org</QPM:VendorEmail>
<QPM:AuthorName>Sam Lantinga</QPM:AuthorName>
<QPM:AuthorURL>http://www.libsdl.org</QPM:AuthorURL>
<QPM:AuthorEmbedURL/>
<QPM:AuthorEmail>slouken@libsdl.org</QPM:AuthorEmail>
<QPM:ProductIconSmall/>
<QPM:ProductIconLarge/>
<QPM:ProductDescriptionShort>SDL_net - is a portable network library for use with SDL.</QPM:ProductDescriptionShort>
<QPM:ProductDescriptionLong>SDL_net - is a portable network library for use with SDL.</QPM:ProductDescriptionLong>
<QPM:ProductDescriptionURL>http://www.libsdl.org</QPM:ProductDescriptionURL>
<QPM:ProductDescriptionEmbedURL/>
</QPM:ProductDescription>
<QPM:ReleaseDescription>
<QPM:ReleaseVersion>@VERSION@</QPM:ReleaseVersion>
<QPM:ReleaseUrgency>High</QPM:ReleaseUrgency>
<QPM:ReleaseStability>Stable</QPM:ReleaseStability>
<QPM:ReleaseNoteMinor/>
<QPM:ReleaseNoteMajor/>
<QPM:ReleaseBuild>1</QPM:ReleaseBuild>
<QPM:CountryExclude/>
<QPM:ReleaseCopyright>GNU General Public License</QPM:ReleaseCopyright>
</QPM:ReleaseDescription>
<QPM:ContentDescription>
<QPM:ContentTopic>Software Development/Libraries and Extensions/C Libraries</QPM:ContentTopic>
<QPM:ContentKeyword>SDL, net, network</QPM:ContentKeyword>
<QPM:Processor/>
<QPM:TargetProcessor/>
<QPM:TargetOS>qnx6</QPM:TargetOS>
<QPM:HostOS>qnx6</QPM:HostOS>
<QPM:DisplayEnvironment>Console</QPM:DisplayEnvironment>
<QPM:TargetAudience>Developer</QPM:TargetAudience>
<QPM:TargetAudience>User</QPM:TargetAudience>
</QPM:ContentDescription>
<QPM:LicenseUrl>repdata://LicenseUrl/COPYING</QPM:LicenseUrl>
<QPM:ProductInstallationDependencies>
<QPM:ProductRequirements/>
</QPM:ProductInstallationDependencies>
</QPM:PackageManifest>
</QPG:PackageFilter>
</QPG:Values>
</QPG:Generation>

View file

@ -1,63 +0,0 @@
%define name @PACKAGE@
%define version @VERSION@
%define release 1
Summary: SDL portable network library
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{version}.tar.gz
URL: http://www.libsdl.org/projects/SDL_net/
License: LGPL
Group: System Environment/Libraries
BuildRoot: /var/tmp/%{name}-buildroot
Prefix: %{_prefix}
Requires: SDL
%description
This is a portable network library for use with SDL.
%package devel
Summary: Libraries and includes to develop SDL networked applications.
Group: Development/Libraries
Requires: %{name}
%description devel
This is a portable network library for use with SDL.
This is the libraries and include files you can use to develop SDL networked applications.
%prep
rm -rf ${RPM_BUILD_ROOT}
%setup -q
%build
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{prefix} --disable-gui
make
%install
rm -rf $RPM_BUILD_ROOT
make install prefix=$RPM_BUILD_ROOT/%{prefix}
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc README CHANGES COPYING
%{prefix}/lib/lib*.so.*
%files devel
%defattr(-,root,root)
%doc README CHANGES COPYING
%{prefix}/lib/lib*.a
%{prefix}/lib/lib*.la
%{prefix}/lib/lib*.so
%{prefix}/include/SDL/
%changelog
* Sat Feb 3 2001 Paul S Jenner <psj@firstlinux.net>
- First spec file based on SDL spec file
# end of file

View file

@ -1,8 +0,0 @@
#!/bin/sh
#
aclocal -I acinclude
automake --foreign --include-deps --add-missing --copy
autoconf
#./configure $*
echo "Now you are ready to run ./configure"

View file

@ -1,483 +0,0 @@
/*
CHAT: A chat client using the SDL example network and GUI libraries
Copyright (C) 1997-2009 Sam Lantinga
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
5635-34 Springhouse Dr.
Pleasanton, CA 94588 (USA)
slouken@devolution.com
*/
/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_net.h"
#ifdef macintosh
#include "GUI.h"
#include "GUI_widgets.h"
#else
#include <GUI/GUI.h>
#include <GUI/GUI_widgets.h>
#endif
#include "chat.h"
/* Global variables */
static TCPsocket tcpsock = NULL;
static UDPsocket udpsock = NULL;
static SDLNet_SocketSet socketset = NULL;
static UDPpacket **packets = NULL;
static struct {
int active;
Uint8 name[256+1];
} people[CHAT_MAXPEOPLE];
static GUI *gui = NULL;
static GUI_TermWin *termwin;
static GUI_TermWin *sendwin;
enum image_names {
IMAGE_QUIT,
IMAGE_SCROLL_UP,
IMAGE_SCROLL_DN,
NUM_IMAGES
};
char *image_files[NUM_IMAGES] = {
"quit.bmp", "scroll_up.bmp", "scroll_dn.bmp"
};
SDL_Surface *images[NUM_IMAGES];
void SendHello(char *name)
{
IPaddress *myip;
char hello[1+1+256];
int i, n;
/* No people are active at first */
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
people[i].active = 0;
}
if ( tcpsock != NULL ) {
/* Get our chat handle */
if ( (name == NULL) &&
((name=getenv("CHAT_USER")) == NULL) &&
((name=getenv("USER")) == NULL ) ) {
name="Unknown";
}
termwin->AddText("Using name '%s'\n", name);
/* Construct the packet */
hello[0] = CHAT_HELLO;
myip = SDLNet_UDP_GetPeerAddress(udpsock, -1);
memcpy(&hello[CHAT_HELLO_PORT], &myip->port, 2);
if ( strlen(name) > 255 ) {
n = 255;
} else {
n = strlen(name);
}
hello[CHAT_HELLO_NLEN] = n;
strncpy(&hello[CHAT_HELLO_NAME], name, n);
hello[CHAT_HELLO_NAME+n++] = 0;
/* Send it to the server */
SDLNet_TCP_Send(tcpsock, hello, CHAT_HELLO_NAME+n);
}
}
void SendBuf(char *buf, int len)
{
int i;
/* Redraw the prompt and add a newline to the buffer */
sendwin->Clear();
sendwin->AddText(CHAT_PROMPT);
buf[len++] = '\n';
/* Send the text to each of our active channels */
for ( i=0; i < CHAT_MAXPEOPLE; ++i ) {
if ( people[i].active ) {
if ( len > packets[0]->maxlen ) {
len = packets[0]->maxlen;
}
memcpy(packets[0]->data, buf, len);
packets[0]->len = len;
SDLNet_UDP_Send(udpsock, i, packets[0]);
}
}
}
void SendKey(SDLKey key, Uint16 unicode)
{
static char keybuf[80-sizeof(CHAT_PROMPT)+1];
static int keypos = 0;
unsigned char ch;
/* We don't handle wide UNICODE characters yet */
if ( unicode > 255 ) {
return;
}
ch = (unsigned char)unicode;
/* Add the key to the buffer, and send it if we have a line */
switch (ch) {
case '\0':
break;
case '\r':
case '\n':
/* Send our line of text */
SendBuf(keybuf, keypos);
keypos = 0;
break;
case '\b':
/* If there's data, back up over it */
if ( keypos > 0 ) {
sendwin->AddText((char *)&ch, 1);
--keypos;
}
break;
default:
/* If the buffer is full, send it */
if ( keypos == (sizeof(keybuf)/sizeof(keybuf[0]))-1 ) {
SendBuf(keybuf, keypos);
keypos = 0;
}
/* Add the text to our send buffer */
sendwin->AddText((char *)&ch, 1);
keybuf[keypos++] = ch;
break;
}
}
int HandleServerData(Uint8 *data)
{
int used;
switch (data[0]) {
case CHAT_ADD: {
Uint8 which;
IPaddress newip;
/* Figure out which channel we got */
which = data[CHAT_ADD_SLOT];
if ((which >= CHAT_MAXPEOPLE) || people[which].active) {
/* Invalid channel?? */
break;
}
/* Get the client IP address */
newip.host=SDLNet_Read32(&data[CHAT_ADD_HOST]);
newip.port=SDLNet_Read16(&data[CHAT_ADD_PORT]);
/* Copy name into channel */
memcpy(people[which].name, &data[CHAT_ADD_NAME], 256);
people[which].name[256] = 0;
people[which].active = 1;
/* Let the user know what happened */
termwin->AddText(
"* New client on %d from %d.%d.%d.%d:%d (%s)\n", which,
(newip.host>>24)&0xFF, (newip.host>>16)&0xFF,
(newip.host>>8)&0xFF, newip.host&0xFF,
newip.port, people[which].name);
/* Put the address back in network form */
newip.host = SDL_SwapBE32(newip.host);
newip.port = SDL_SwapBE16(newip.port);
/* Bind the address to the UDP socket */
SDLNet_UDP_Bind(udpsock, which, &newip);
}
used = CHAT_ADD_NAME+data[CHAT_ADD_NLEN];
break;
case CHAT_DEL: {
Uint8 which;
/* Figure out which channel we lost */
which = data[CHAT_DEL_SLOT];
if ( (which >= CHAT_MAXPEOPLE) ||
! people[which].active ) {
/* Invalid channel?? */
break;
}
people[which].active = 0;
/* Let the user know what happened */
termwin->AddText(
"* Lost client on %d (%s)\n", which, people[which].name);
/* Unbind the address on the UDP socket */
SDLNet_UDP_Unbind(udpsock, which);
}
used = CHAT_DEL_LEN;
break;
case CHAT_BYE: {
termwin->AddText("* Chat server full\n");
}
used = CHAT_BYE_LEN;
break;
default: {
/* Unknown packet type?? */;
}
used = 0;
break;
}
return(used);
}
void HandleServer(void)
{
Uint8 data[512];
int pos, len;
int used;
/* Has the connection been lost with the server? */
len = SDLNet_TCP_Recv(tcpsock, (char *)data, 512);
if ( len <= 0 ) {
SDLNet_TCP_DelSocket(socketset, tcpsock);
SDLNet_TCP_Close(tcpsock);
tcpsock = NULL;
termwin->AddText("Connection with server lost!\n");
} else {
pos = 0;
while ( len > 0 ) {
used = HandleServerData(&data[pos]);
pos += used;
len -= used;
if ( used == 0 ) {
/* We might lose data here.. oh well,
we got a corrupt packet from server
*/
len = 0;
}
}
}
}
void HandleClient(void)
{
int n;
n = SDLNet_UDP_RecvV(udpsock, packets);
while ( n-- > 0 ) {
if ( packets[n]->channel >= 0 ) {
termwin->AddText("[%s] ",
people[packets[n]->channel].name);
termwin->AddText((char *)packets[n]->data, packets[n]->len);
}
}
}
GUI_status HandleNet(void)
{
SDLNet_CheckSockets(socketset, 0);
if ( SDLNet_SocketReady(tcpsock) ) {
HandleServer();
}
if ( SDLNet_SocketReady(udpsock) ) {
HandleClient();
}
/* Redraw the screen if the window changed */
if ( termwin->Changed() ) {
return(GUI_REDRAW);
} else {
return(GUI_PASS);
}
}
void InitGUI(SDL_Surface *screen)
{
int x1, y1, y2;
SDL_Rect empty_rect = { 0, 0, 0, 0 };
GUI_Widget *widget;
gui = new GUI(screen);
/* Chat terminal window */
termwin = new GUI_TermWin(0, 0, 80*8, 50*8, NULL,NULL,CHAT_SCROLLBACK);
gui->AddWidget(termwin);
/* Send-line window */
y1 = termwin->H()+2;
sendwin = new GUI_TermWin(0, y1, 80*8, 1*8, NULL, SendKey, 0);
sendwin->AddText(CHAT_PROMPT);
gui->AddWidget(sendwin);
/* Add scroll buttons for main window */
y1 += sendwin->H()+2;
y2 = y1+images[IMAGE_SCROLL_UP]->h;
widget = new GUI_ScrollButtons(2, y1, images[IMAGE_SCROLL_UP],
empty_rect, 2, y2, images[IMAGE_SCROLL_DN],
SCROLLBAR_VERTICAL, termwin);
gui->AddWidget(widget);
/* Add QUIT button */
x1 = (screen->w-images[IMAGE_QUIT]->w)/2;
y1 = sendwin->Y()+sendwin->H()+images[IMAGE_QUIT]->h/2;
widget = new GUI_Button(NULL, x1, y1, images[IMAGE_QUIT], NULL);
gui->AddWidget(widget);
/* That's all folks */
return;
}
extern "C"
void cleanup(int exitcode)
{
int i;
/* Clean up the GUI */
if ( gui ) {
delete gui;
gui = NULL;
}
/* Clean up any images we have */
for ( i=0; i<NUM_IMAGES; ++i ) {
if ( images[i] ) {
SDL_FreeSurface(images[i]);
images[i] = NULL;
}
}
/* Close the network connections */
if ( tcpsock != NULL ) {
SDLNet_TCP_Close(tcpsock);
tcpsock = NULL;
}
if ( udpsock != NULL ) {
SDLNet_UDP_Close(udpsock);
udpsock = NULL;
}
if ( socketset != NULL ) {
SDLNet_FreeSocketSet(socketset);
socketset = NULL;
}
if ( packets != NULL ) {
SDLNet_FreePacketV(packets);
packets = NULL;
}
SDLNet_Quit();
SDL_Quit();
exit(exitcode);
}
int main(int argc, char *argv[])
{
SDL_Surface *screen;
int i;
char *server;
IPaddress serverIP;
/* Check command line arguments */
if ( argv[1] == NULL ) {
fprintf(stderr, "Usage: %s <server>\n", argv[0]);
exit(1);
}
/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(1);
}
/* Set a 640x480 video mode -- allows 80x50 window using 8x8 font */
screen = SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
SDL_Quit();
exit(1);
}
/* Initialize the network */
if ( SDLNet_Init() < 0 ) {
fprintf(stderr, "Couldn't initialize net: %s\n",
SDLNet_GetError());
SDL_Quit();
exit(1);
}
/* Get ready to initialize all of our data */
/* Load the display font and other images */
for ( i=0; i<NUM_IMAGES; ++i ) {
images[i] = NULL;
}
for ( i=0; i<NUM_IMAGES; ++i ) {
images[i] = SDL_LoadBMP(image_files[i]);
if ( images[i] == NULL ) {
fprintf(stderr, "Couldn't load '%s': %s\n",
image_files[i], SDL_GetError());
cleanup(2);
}
}
/* Go! */
InitGUI(screen);
/* Allocate a vector of packets for client messages */
packets = SDLNet_AllocPacketV(4, CHAT_PACKETSIZE);
if ( packets == NULL ) {
fprintf(stderr, "Couldn't allocate packets: Out of memory\n");
cleanup(2);
}
/* Connect to remote host and create UDP endpoint */
server = argv[1];
termwin->AddText("Connecting to %s ... ", server);
gui->Display();
SDLNet_ResolveHost(&serverIP, server, CHAT_PORT);
if ( serverIP.host == INADDR_NONE ) {
termwin->AddText("Couldn't resolve hostname\n");
} else {
/* If we fail, it's okay, the GUI shows the problem */
tcpsock = SDLNet_TCP_Open(&serverIP);
if ( tcpsock == NULL ) {
termwin->AddText("Connect failed\n");
} else {
termwin->AddText("Connected\n");
}
}
/* Try ports in the range {CHAT_PORT - CHAT_PORT+10} */
for ( i=0; (udpsock == NULL) && i<10; ++i ) {
udpsock = SDLNet_UDP_Open(CHAT_PORT+i);
}
if ( udpsock == NULL ) {
SDLNet_TCP_Close(tcpsock);
tcpsock = NULL;
termwin->AddText("Couldn't create UDP endpoint\n");
}
/* Allocate the socket set for polling the network */
socketset = SDLNet_AllocSocketSet(2);
if ( socketset == NULL ) {
fprintf(stderr, "Couldn't create socket set: %s\n",
SDLNet_GetError());
cleanup(2);
}
SDLNet_TCP_AddSocket(socketset, tcpsock);
SDLNet_UDP_AddSocket(socketset, udpsock);
/* Run the GUI, handling network data */
SendHello(argv[2]);
gui->Run(HandleNet);
cleanup(0);
/* Keep the compiler happy */
return(0);
}

View file

@ -1,54 +0,0 @@
/*
CHAT: A chat client/server using the SDL example network library
Copyright (C) 1997-2009 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
*/
/* $Id: chat.h 4211 2008-12-08 00:27:32Z slouken $ */
/* Convert four letters into a number */
#define MAKE_NUM(A, B, C, D) (((A+B)<<8)|(C+D))
/* Defines for the chat client */
#define CHAT_SCROLLBACK 512 /* Save 512 lines in scrollback */
#define CHAT_PROMPT "> "
#define CHAT_PACKETSIZE 256 /* Maximum length of a message */
/* Defines shared between the server and client */
#define CHAT_PORT MAKE_NUM('C','H','A','T')
/* The protocol between the chat client and server */
#define CHAT_HELLO 0 /* 0+Port+len+name */
#define CHAT_HELLO_PORT 1
#define CHAT_HELLO_NLEN CHAT_HELLO_PORT+2
#define CHAT_HELLO_NAME CHAT_HELLO_NLEN+1
#define CHAT_ADD 1 /* 1+N+IP+Port+len+name */
#define CHAT_ADD_SLOT 1
#define CHAT_ADD_HOST CHAT_ADD_SLOT+1
#define CHAT_ADD_PORT CHAT_ADD_HOST+4
#define CHAT_ADD_NLEN CHAT_ADD_PORT+2
#define CHAT_ADD_NAME CHAT_ADD_NLEN+1
#define CHAT_DEL 2 /* 2+N */
#define CHAT_DEL_SLOT 1
#define CHAT_DEL_LEN CHAT_DEL_SLOT+1
#define CHAT_BYE 255 /* 255 */
#define CHAT_BYE_LEN 1
/* The maximum number of people who can talk at once */
#define CHAT_MAXPEOPLE 10

View file

@ -1,260 +0,0 @@
/*
CHATD: A chat server using the SDL example network library
Copyright (C) 1997-2009 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#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<CHAT_MAXPEOPLE; ++which ) {
if ( ! people[which].sock ) {
break;
}
}
if ( which == CHAT_MAXPEOPLE ) {
/* Look for inactive person slot */
for ( which=0; which<CHAT_MAXPEOPLE; ++which ) {
if ( people[which].sock && ! people[which].active ) {
/* Kick them out.. */
data = CHAT_BYE;
SDLNet_TCP_Send(people[which].sock, &data, 1);
SDLNet_TCP_DelSocket(socketset,
people[which].sock);
SDLNet_TCP_Close(people[which].sock);
#ifdef DEBUG
fprintf(stderr, "Killed inactive socket %d\n", which);
#endif
break;
}
}
}
if ( which == CHAT_MAXPEOPLE ) {
/* No more room... */
data = CHAT_BYE;
SDLNet_TCP_Send(newsock, &data, 1);
SDLNet_TCP_Close(newsock);
#ifdef DEBUG
fprintf(stderr, "Connection refused -- chat room full\n");
#endif
} else {
/* Add socket as an inactive person */
people[which].sock = newsock;
people[which].peer = *SDLNet_TCP_GetPeerAddress(newsock);
SDLNet_TCP_AddSocket(socketset, people[which].sock);
#ifdef DEBUG
fprintf(stderr, "New inactive socket %d\n", which);
#endif
}
}
/* Send a "new client" notification */
void SendNew(int about, int to)
{
char data[512];
int n;
n = strlen((char *)people[about].name)+1;
data[0] = CHAT_ADD;
data[CHAT_ADD_SLOT] = about;
memcpy(&data[CHAT_ADD_HOST], &people[about].peer.host, 4);
memcpy(&data[CHAT_ADD_PORT], &people[about].peer.port, 2);
data[CHAT_ADD_NLEN] = n;
memcpy(&data[CHAT_ADD_NAME], people[about].name, n);
SDLNet_TCP_Send(people[to].sock, data, CHAT_ADD_NAME+n);
}
void HandleClient(int which)
{
char data[512];
int i;
/* Has the connection been closed? */
if ( SDLNet_TCP_Recv(people[which].sock, data, 512) <= 0 ) {
#ifdef DEBUG
fprintf(stderr, "Closing socket %d (was%s active)\n",
which, people[which].active ? "" : " not");
#endif
/* Notify all active clients */
if ( people[which].active ) {
people[which].active = 0;
data[0] = CHAT_DEL;
data[CHAT_DEL_SLOT] = which;
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
if ( people[i].active ) {
SDLNet_TCP_Send(people[i].sock,data,CHAT_DEL_LEN);
}
}
}
SDLNet_TCP_DelSocket(socketset, people[which].sock);
SDLNet_TCP_Close(people[which].sock);
people[which].sock = NULL;
} else {
switch (data[0]) {
case CHAT_HELLO: {
/* Yay! An active connection */
memcpy(&people[which].peer.port,
&data[CHAT_HELLO_PORT], 2);
memcpy(people[which].name,
&data[CHAT_HELLO_NAME], 256);
people[which].name[256] = 0;
#ifdef DEBUG
fprintf(stderr, "Activating socket %d (%s)\n",
which, people[which].name);
#endif
/* Notify all active clients */
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
if ( people[i].active ) {
SendNew(which, i);
}
}
/* Notify about all active clients */
people[which].active = 1;
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
if ( people[i].active ) {
SendNew(i, which);
}
}
}
break;
default: {
/* Unknown packet type?? */;
}
break;
}
}
}
static void cleanup(int exitcode)
{
if ( servsock != NULL ) {
SDLNet_TCP_Close(servsock);
servsock = NULL;
}
if ( socketset != NULL ) {
SDLNet_FreeSocketSet(socketset);
socketset = NULL;
}
SDLNet_Quit();
SDL_Quit();
exit(exitcode);
}
int main(int argc, char *argv[])
{
IPaddress serverIP;
int i;
/* Initialize SDL */
if ( SDL_Init(0) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(1);
}
/* Initialize the network */
if ( SDLNet_Init() < 0 ) {
fprintf(stderr, "Couldn't initialize net: %s\n",
SDLNet_GetError());
SDL_Quit();
exit(1);
}
/* Initialize the channels */
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
people[i].active = 0;
people[i].sock = NULL;
}
/* Allocate the socket set */
socketset = SDLNet_AllocSocketSet(CHAT_MAXPEOPLE+1);
if ( socketset == NULL ) {
fprintf(stderr, "Couldn't create socket set: %s\n",
SDLNet_GetError());
cleanup(2);
}
/* Create the server socket */
SDLNet_ResolveHost(&serverIP, NULL, CHAT_PORT);
printf("Server IP: %x, %d\n", serverIP.host, serverIP.port);
servsock = SDLNet_TCP_Open(&serverIP);
if ( servsock == NULL ) {
fprintf(stderr, "Couldn't create server socket: %s\n",
SDLNet_GetError());
cleanup(2);
}
SDLNet_TCP_AddSocket(socketset, servsock);
/* Loop, waiting for network events */
for ( ; ; ) {
/* Wait for events */
SDLNet_CheckSockets(socketset, ~0);
/* Check for new connections */
if ( SDLNet_SocketReady(servsock) ) {
HandleServer();
}
/* Check for events on existing clients */
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
if ( SDLNet_SocketReady(people[i].sock) ) {
HandleClient(i);
}
}
}
cleanup(0);
/* Not reached, but fixes compiler warnings */
return 0;
}

1555
SDL_net/src/config.guess vendored

File diff suppressed because it is too large Load diff

1685
SDL_net/src/config.sub vendored

File diff suppressed because it is too large Load diff

View file

@ -1,134 +0,0 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(README)
dnl Set various version strings - taken gratefully from the GTk sources
# Making releases:
# MICRO_VERSION += 1;
# INTERFACE_AGE += 1;
# BINARY_AGE += 1;
# if any functions have been added, set INTERFACE_AGE to 0.
# if backwards compatibility has been broken,
# set BINARY_AGE and INTERFACE_AGE to 0.
MAJOR_VERSION=1
MINOR_VERSION=2
MICRO_VERSION=7
INTERFACE_AGE=7
BINARY_AGE=7
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
AC_SUBST(MAJOR_VERSION)
AC_SUBST(MINOR_VERSION)
AC_SUBST(MICRO_VERSION)
AC_SUBST(INTERFACE_AGE)
AC_SUBST(BINARY_AGE)
AC_SUBST(VERSION)
# libtool versioning
LT_RELEASE=$MAJOR_VERSION.$MINOR_VERSION
LT_CURRENT=`expr $MICRO_VERSION - $INTERFACE_AGE`
LT_REVISION=$INTERFACE_AGE
LT_AGE=`expr $BINARY_AGE - $INTERFACE_AGE`
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
dnl Detect the canonical build and host environments
AC_CANONICAL_HOST
dnl Setup for automake
AM_INIT_AUTOMAKE(SDL_net, $VERSION)
dnl Check for tools
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
if test -z "$host_alias"; then
hostaliaswindres=
else
hostaliaswindres="$host_alias-windres"
fi
AC_CHECK_PROGS(WINDRES, [windres $hostaliaswindres $host_os-windres])
case "$host" in
*-*-beos*)
ac_default_prefix=/boot/develop/tools/gnupro
;;
*-*-cygwin* | *-*-mingw32*)
if test "$build" != "$host"; then # cross-compiling
# Default cross-compile location
ac_default_prefix=/usr/local/cross-tools/i386-mingw32
else
# Look for the location of the tools and install there
if test "$BUILD_PREFIX" != ""; then
ac_default_prefix=$BUILD_PREFIX
fi
fi
if test x$WINDRES != x; then
use_version_rc=true
fi
;;
esac
AM_CONDITIONAL(USE_VERSION_RC, test x$use_version_rc = xtrue)
dnl Figure out which networking libraries to use
case "$host" in
*-*-cygwin* | *-*-mingw32*)
INETLIB="-lwsock32"
;;
sparc*-*-solaris*)
INETLIB="-lsocket -lnsl"
;;
*-*-qnx*)
INETLIB="-lsocket"
;;
*-*-beos*)
INETLIB=""
;;
*)
INETLIB=""
;;
esac
AC_SUBST(INETLIB)
dnl Check for SDL
SDL_VERSION=1.2.4
AM_PATH_SDL($SDL_VERSION,
:,
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
)
CFLAGS="$CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"
dnl Check for GUI library for the chat client
have_GUI=no
AC_ARG_ENABLE(gui,
[ --enable-gui Try to build the GUI test programs [default=yes]],
, enable_gui=yes)
if test x$enable_gui = xyes; then
AC_CHECK_LIB(GUI, GUI_Create, have_GUI=yes)
if test x$have_GUI != xyes; then
AC_MSG_WARN([*** Can't find the GUI library - not building test programs
The GUI library can be found at:
http://www.libsdl.org/projects/GUIlib/
])
fi
fi
AM_CONDITIONAL(HAVE_GUI_LIB, test x$have_GUI = xyes)
dnl C++ flags are the same as the C flags
CXXFLAGS="$CXXFLAGS $CFLAGS"
AC_SUBST([WINDRES])
# Finally create all the generated files
AC_OUTPUT([
Makefile SDL_net.spec SDL_net.qpg
])

File diff suppressed because it is too large Load diff