34 #include "GUI_widgets.h"
37 #include <GUI/GUI_widgets.h>
62 "quit.bmp",
"scroll_up.bmp",
"scroll_dn.bmp"
79 if ( (name ==
NULL) &&
80 ((name=getenv(
"CHAT_USER")) ==
NULL) &&
81 ((name=getenv(
"USER")) ==
NULL ) ) {
84 termwin->AddText(
"Using name '%s'\n", name);
90 if ( strlen(name) > 255 ) {
97 hello[CHAT_HELLO_NAME+n++] = 0;
116 if ( len > packets[0]->maxlen ) {
128 static int keypos = 0;
132 if ( unicode > 255 ) {
135 ch = (
unsigned char)unicode;
150 sendwin->AddText((
char *)&ch, 1);
156 if ( keypos == (
sizeof(keybuf)/
sizeof(keybuf[0]))-1 ) {
161 sendwin->AddText((
char *)&ch, 1);
162 keybuf[keypos++] = ch;
188 people[which].name[256] = 0;
193 "* New client on %d from %d.%d.%d.%d:%d (%s)\n", which,
194 (newip.
host>>24)&0xFF, (newip.
host>>16)&0xFF,
195 (newip.
host>>8)&0xFF, newip.
host&0xFF,
221 "* Lost client on %d (%s)\n", which,
people[which].
name);
229 termwin->AddText(
"* Chat server full\n");
254 termwin->AddText(
"Connection with server lost!\n");
276 if ( packets[n]->channel >= 0 ) {
305 SDL_Rect empty_rect = { 0, 0, 0, 0 };
308 gui =
new GUI(screen);
326 gui->AddWidget(widget);
332 gui->AddWidget(widget);
368 if ( packets !=
NULL ) {
377 int main(
int argc,
char *argv[])
385 if ( argv[1] ==
NULL ) {
386 fprintf(stderr,
"Usage: %s <server>\n", argv[0]);
392 fprintf(stderr,
"Couldn't initialize SDL: %s\n",
SDL_GetError());
398 if ( screen ==
NULL ) {
399 fprintf(stderr,
"Couldn't set video mode: %s\n",
SDL_GetError());
406 fprintf(stderr,
"Couldn't initialize net: %s\n",
420 if ( images[i] ==
NULL ) {
421 fprintf(stderr,
"Couldn't load '%s': %s\n",
432 if ( packets ==
NULL ) {
433 fprintf(stderr,
"Couldn't allocate packets: Out of memory\n");
439 termwin->AddText(
"Connecting to %s ... ", server);
443 termwin->AddText(
"Couldn't resolve hostname\n");
448 termwin->AddText(
"Connect failed\n");
450 termwin->AddText(
"Connected\n");
460 termwin->AddText(
"Couldn't create UDP endpoint\n");
466 fprintf(stderr,
"Couldn't create socket set: %s\n",
DECLSPEC int SDLCALL SDLNet_TCP_Send(TCPsocket sock, const void *data, int len)
char * image_files[NUM_IMAGES]
DECLSPEC int SDLCALL SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout)
DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface)
static GUI_TermWin * sendwin
struct _UDPsocket * UDPsocket
DECLSPEC UDPsocket SDLCALL SDLNet_UDP_Open(Uint16 port)
int main(int argc, char **argv)
#define SDLNet_SocketReady(sock)
#define SDL_LoadBMP(file)
DECLSPEC void SDLCALL SDLNet_FreeSocketSet(SDLNet_SocketSet set)
static SDLNet_SocketSet socketset
DECLSPEC int SDLCALL SDLNet_Init(void)
A collection of pixels used in software blitting.
SDL_Surface * images[NUM_IMAGES]
EGLImageKHR EGLint * name
DECLSPEC void SDLCALL SDL_Quit(void)
DECLSPEC const char *SDLCALL SDL_GetError(void)
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLfixed GLfixed GLfixed y2
void SendHello(char *name)
DECLSPEC void SDLCALL SDLNet_UDP_Unbind(UDPsocket sock, int channel)
static UDPpacket ** packets
static __inline__ int SDLNet_TCP_AddSocket(SDLNet_SocketSet set, TCPsocket sock)
static __inline__ int SDLNet_UDP_AddSocket(SDLNet_SocketSet set, UDPsocket sock)
int HandleServerData(Uint8 *data)
void SendKey(SDLKey key, Uint16 unicode)
struct _SDLNet_SocketSet * SDLNet_SocketSet
GUI_status HandleNet(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
DECLSPEC void SDLCALL SDLNet_FreePacketV(UDPpacket **packetV)
DECLSPEC UDPpacket **SDLCALL SDLNet_AllocPacketV(int howmany, int size)
DECLSPEC TCPsocket SDLCALL SDLNet_TCP_Open(IPaddress *ip)
#define SDLNet_Read32(areap)
DECLSPEC void SDLCALL SDLNet_Quit(void)
DECLSPEC int SDLCALL SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet)
void cleanup(int exitcode)
void InitGUI(SDL_Surface *screen)
GLuint GLfloat GLfloat GLfloat x1
DECLSPEC int SDLCALL SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
static struct @97 people[CHAT_MAXPEOPLE]
GLenum GLuint GLsizei const GLchar * buf
struct _TCPsocket * TCPsocket
uint8_t Uint8
An unsigned 8-bit integer type.
void SendBuf(char *buf, int len)
static GUI_TermWin * termwin
static __inline__ int SDLNet_TCP_DelSocket(SDLNet_SocketSet set, TCPsocket sock)
DECLSPEC void SDLCALL SDLNet_UDP_Close(UDPsocket sock)
DECLSPEC int SDLCALL SDLNet_UDP_Bind(UDPsocket sock, int channel, const IPaddress *address)
DECLSPEC IPaddress *SDLCALL SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel)
DECLSPEC int SDLCALL SDL_Init(Uint32 flags)
DECLSPEC SDLNet_SocketSet SDLCALL SDLNet_AllocSocketSet(int maxsockets)
DECLSPEC int SDLCALL SDLNet_TCP_Recv(TCPsocket sock, void *data, int maxlen)
uint16_t Uint16
An unsigned 16-bit integer type.
#define SDLNet_Read16(areap)
DECLSPEC void SDLCALL SDLNet_TCP_Close(TCPsocket sock)
A rectangle, with the origin at the upper left.
DECLSPEC const char *SDLCALL SDLNet_GetError(void)
DECLSPEC int SDLCALL SDLNet_UDP_RecvV(UDPsocket sock, UDPpacket **packets)