15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <sys/ioctl.h>
19 #include <sys/filio.h>
21 #include <netinet/in.h>
22 #include <sys/select.h>
24 #include <arpa/inet.h>
27 #define WSAGetLastError() (errno)
36 #define MAXCHATBUFFER 500
69 #define SSIZE(x) (sizeof((x))-1)
71 #define SSIZE(x) (sizeof((x)))
114 char chat_server[50];
116 unsigned long argp = 1;
117 char signon_str[100];
132 p = strchr(serveraddr,
':');
139 memset(chat_server, 0,
sizeof(chat_server));
140 strncpy(chat_server,serveraddr,(p-serveraddr));
141 chat_server[p-serveraddr] =
'\0';
142 chat_port = (short)atoi(p+1);
148 Chatsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
157 Chataddr.sin_addr.s_addr = INADDR_ANY;
168 iaddr = inet_addr( chat_server );
169 if ( iaddr == INADDR_NONE ) {
171 he = gethostbyname(chat_server);
176 memcpy(&iaddr, he->h_addr_list[0],4);
179 memcpy(&
Chataddr.sin_addr.s_addr, &iaddr,4);
181 Chataddr.sin_port = htons( chat_port );
209 fd_set write_fds,error_fds;
218 if (select(
Chatsock+1, NULL, &write_fds, NULL, &timeout) > 0)
222 size_t err_val_size =
sizeof(err_val);
223 getsockopt(
Chatsock, SOL_SOCKET, SO_ERROR, (
char*)&err_val, (
socklen_t*)&err_val_size);
236 memset(signon_str, 0,
sizeof(signon_str));
247 if ( select(
Chatsock+1, NULL, NULL, &error_fds, &timeout) )
311 szCmd[
sizeof(szCmd)-1] =
'\0';
312 szTarget[
sizeof(szTarget)-1] =
'\0';
318 strncpy(szCmd,
GetWordNum(0, line+1),
sizeof(szCmd)-1);
321 strncpy(szTarget,
GetWordNum(1, line+1),
sizeof(szTarget)-1);
322 snprintf(szCmd,
SSIZE(szCmd),
NOX(
"PRIVMSG %s :%s\n\r"), szTarget, line+strlen(
NOX(
"/msg "))+strlen(szTarget)+1);
323 send(
Chatsock,szCmd,strlen(szCmd),0);
324 szCmd[strlen(szCmd)-2] =
'\0';
331 send(
Chatsock,szCmd,strlen(szCmd),0);
332 szCmd[strlen(szCmd)-2] =
'\0';
339 snprintf(szCmd,
SSIZE(szCmd),
"%s\n\r", line+strlen(
NOX(
"/xyz ")));
340 send(
Chatsock,szCmd,strlen(szCmd),0);
345 snprintf(szCmd,
SSIZE(szCmd),
"%s\n\r", line+1);
346 send(
Chatsock,szCmd,strlen(szCmd),0);
351 snprintf(szCmd,
SSIZE(szCmd),
"%s\n\r", line+1);
352 send(
Chatsock,szCmd,strlen(szCmd),0);
355 return XSTR(
"Unrecognized command",634);
363 send(
Chatsock,szCmd,strlen(szCmd),0);
364 if(strlen(szCmd) >= 2){
365 szCmd[strlen(szCmd)-2] =
'\0';
393 int iuser_list_length = 0;;
404 iuser_list_length += strlen(Curruser->
nick_name)+1;
405 Curruser = Curruser->
next;
414 Curruser = Curruser->
next;
434 partstr[
sizeof(partstr)-1] =
'\0';
486 while ( select(0, &read_fds, NULL, NULL, &timeout) )
488 while ( select(
Chatsock+1, &read_fds, NULL, NULL, &timeout) )
496 if((ch[0] == 0x0a)||(ch[0]==0x0d))
527 static char strreturn[600];
528 static char ptokstr[600];
529 char seps[10] =
NOX(
" \n\r\t");
530 char *token,*strstart;
532 strreturn[
sizeof(strreturn)-1] =
'\0';
533 ptokstr[
sizeof(ptokstr)-1] =
'\0';
537 strncpy(ptokstr, l_String,
sizeof(ptokstr)-1);
539 token=strtok(ptokstr,seps);
543 token=strtok(NULL,seps);
547 strncpy(strreturn, token,
sizeof(strreturn)-1);
557 strncpy(strreturn, l_String+((token-strstart)+1),
sizeof(strreturn)-1);
570 Curruser = Curruser->
next;
579 Firstuser->
next = NULL;
585 while(Curruser->
next)
587 Curruser = Curruser->
next;
590 Curruser = Curruser->
next;
593 Curruser->
next = NULL;
616 Firstuser = Curruser->
next;
623 Curruser = Curruser->
next;
635 tmp_user = Curruser->
next;
676 strncpy(szRemLine, Line,
sizeof(szRemLine)-1);
682 strncpy(szPrefix, pszTempStr,
sizeof(szPrefix)-1);
683 strncpy(szHackPrefix, pszTempStr,
sizeof(szHackPrefix)-1);
684 strncpy(szRemLine, Line+1+strlen(szPrefix),
sizeof(szRemLine)-1);
687 pszTempStr=strtok(szHackPrefix,
"!");
690 strncpy(szNick, pszTempStr,
sizeof(szNick)-1);
694 strncpy(szNick,szPrefix,31);
697 iPrefixLen=strlen(szPrefix);
701 strncpy(szRemLine, Line,
sizeof(szRemLine)-1);
702 strncpy(szNick,
Nick_name,
sizeof(szNick)-1);
703 strncpy(szPrefix,
Nick_name,
sizeof(szPrefix)-1);
710 strncpy(szCmd, pszTempStr,
sizeof(szCmd)-1);
719 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+2,
sizeof(szRemLine)-1);
724 strncpy(szTarget, pszTempStr,
sizeof(szTarget)-1);
725 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4,
sizeof(szRemLine)-1);
726 if(szRemLine[0]==
':')
728 strncpy(szCTCPCmd,
GetWordNum(0,szRemLine+1),
sizeof(szCTCPCmd)-1);
729 if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00;
734 strncpy(szCTCPCmd,
GetWordNum(0,szRemLine),
sizeof(szCTCPCmd)-1);
735 if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00;
737 if(szCTCPCmd[0]==0x01)
740 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+strlen(szCTCPCmd)+6,
sizeof(szRemLine)-1);
741 szRemLine[strlen(szRemLine)-1] =
'\0';
745 snprintf(szResponse,
SSIZE(szResponse),
"* %s %s", szNick, szRemLine);
750 strncpy(szHackPrefix, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4,
sizeof(szHackPrefix)-1);
751 szRemLine[strlen(szRemLine)-1] =
'\0';
752 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"** CTCP %s %s %s"), szTarget, szCTCPCmd+1, szRemLine);
757 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"/NOTICE %s :\001PING %s\001"), szNick, szRemLine);
765 strncpy(szRemLine, 1 +
GetWordNum(0,Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4),
sizeof(szRemLine)-1);
766 szRemLine[strlen(szRemLine)-1] =
'\0';
767 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"** CTCP Message from %s (%s)"), szNick, szRemLine);
775 snprintf(szResponse,
SSIZE(szResponse),
"[%s] %s", szNick, pszTempStr);
783 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"Private Message to <%s>: %s"), szNick, pszTempStr);
788 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"Private Message from <%s>: %s"), szNick, pszTempStr);
805 strncpy(szTarget, pszTempStr,
sizeof(szTarget)-1);
806 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4,
sizeof(szRemLine)-1);
807 if(szRemLine[0]==
':')
809 strncpy(szCTCPCmd,
GetWordNum(0,szRemLine+1),
sizeof(szCTCPCmd)-1);
810 if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00;
815 strncpy(szCTCPCmd,
GetWordNum(0,szRemLine),
sizeof(szCTCPCmd)-1);
816 if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00;
818 if(szCTCPCmd[0]==0x01)
821 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+strlen(szCTCPCmd)+6,
sizeof(szRemLine)-1);
822 szRemLine[strlen(szRemLine)-1] =
'\0';
829 strncpy(szRemLine, 1 +
GetWordNum(0,Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4),
sizeof(szRemLine)-1);
830 szRemLine[strlen(szRemLine)-1] =
'\0';
831 snprintf(szResponse,
SSIZE(szResponse),
XSTR(
"** CTCP Message from %s (%s)", 635), szNick, szRemLine);
835 snprintf(szResponse,
SSIZE(szResponse),
"%s", szRemLine);
853 strncpy(szTarget, pszTempStr,
sizeof(szTarget)-1);
856 snprintf(szResponse,
SSIZE(szResponse),
XSTR(
"** %s has joined %s", 636), szNick, szTarget);
863 strncpy(szTarget, pszTempStr,
sizeof(szTarget)-1);
864 strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+3,
sizeof(szRemLine)-1);
878 strncpy(szTarget, pszTempStr,
sizeof(szTarget)-1);
880 strncpy(szHackPrefix, pszTempStr,
sizeof(szHackPrefix)-1);
890 snprintf(szResponse,
SSIZE(szResponse),
XSTR(
"*** %s has kicked %s from channel %s (%s)", 637), szNick, szHackPrefix, szTarget, pszTempStr);
905 snprintf(nicks,
SSIZE(nicks),
"%s %s", szNick,
GetWordNum(0, szRemLine));
909 snprintf(szResponse,
SSIZE(szResponse),
XSTR(
"*** %s is now known as %s", 638), szNick,
GetWordNum(0, szRemLine));
936 char szWhoisUser[33];
937 memset(szWhoisUser, 0,
sizeof(szWhoisUser));
938 strncpy(szWhoisUser,
GetWordNum(1,szRemLine),
sizeof(szWhoisUser)-1);
942 snprintf(szResponse,
SSIZE(szResponse),
XSTR(
"**Error: %s is not online!", 639), szWhoisUser);
948 char szWhoisUser[33];
949 memset(szWhoisUser, 0,
sizeof(szWhoisUser));
950 strncpy(szWhoisUser,
GetWordNum(1,szRemLine),
sizeof(szWhoisUser)-1);
957 char szWhoisUser[33];
958 memset(szWhoisUser, 0,
sizeof(szWhoisUser));
959 strncpy(szWhoisUser,
GetWordNum(1,szRemLine),
sizeof(szWhoisUser)-1);
987 char channel_list_name[33];
989 memset(channel_list_name, 0,
sizeof(channel_list_name));
990 memset(sztopic, 0,
sizeof(sztopic));
991 strncpy(sztopic,
GetWordNum(3,szRemLine),
sizeof(sztopic)-1);
992 strncpy(channel_list_name,
GetWordNum(1,szRemLine),
sizeof(channel_list_name)-1);
1047 if((
stricmp(szCmd,
"377")==0)||
1056 if(((
stricmp(szCmd,
"366")==0))||
1067 pszTempStr =
GetWordNum(3,Line+iPrefixLen+strlen(szCmd)+2);
1068 strncpy(szRemLine, pszTempStr,
sizeof(szRemLine)-1);
1069 pszTempStr = strtok(szRemLine,
" ");
1073 if(pszTempStr[0]==
'@')
1077 else if(pszTempStr[0]==
'+')
1085 pszTempStr=strtok(NULL,
" ");
1090 if((
stricmp(szCmd,
"001")==0)||
1108 snprintf(szResponse,
SSIZE(szResponse),
"%s",
XSTR(
"Your nickname contains invalid characters", 640));
1119 snprintf(szResponse,
SSIZE(szResponse),
NOX(
"/NICK %s"), new_nick);
1124 strncpy(szResponse, Line,
sizeof(szResponse)-1);
1133 if(Firstcommand==NULL)
1137 Firstcommand->
next = NULL;
1142 while(Currcommand->
next)
1144 Currcommand = Currcommand->
next;
1148 Currcommand = Currcommand->
next;
1150 Currcommand->
command = (short)command;
1151 if(len&&data) memcpy(&Currcommand->
data,data,len);
1152 Currcommand->
next = NULL;
1160 if(!Firstcommand)
return NULL;
1162 memcpy(&response_cmd,Currcommand,
sizeof(
Chat_command));
1163 tmp_cmd = Currcommand->
next;
1165 Firstcommand = tmp_cmd;
1166 return &response_cmd;
1176 tmp_cmd = Currcommand->
next;
1178 Currcommand = tmp_cmd;
1180 Firstcommand = NULL;
1191 tmp_chan = Currchannel->
next;
1193 Currchannel = tmp_chan;
1195 Firstchannel = NULL;
1201 int ichan_list_length = 0;
1202 char sznumusers[10];
1217 ichan_list_length += strlen(Currchannel->
topic)+1+strlen(Currchannel->
channel_name)+1+5;
1218 Currchannel = Currchannel->
next;
1222 memset(
Chan_list, 0, ichan_list_length+1);
1232 Currchannel = Currchannel->
next;
1242 if(Firstchannel==NULL)
1247 strncpy(Firstchannel->
topic, topic,
sizeof(Firstchannel->
topic)-1);
1248 Firstchannel->
users = numusers;
1249 Firstchannel->
next = NULL;
1254 while(Currchannel->
next)
1256 Currchannel = Currchannel->
next;
1260 Currchannel = Currchannel->
next;
1262 strncpy(Currchannel->
topic, topic,
sizeof(Currchannel->
topic)-1);
1263 Currchannel->
users = numusers;
1265 Currchannel->
next = NULL;
1272 char szWhoisCmd[100];
1293 snprintf(szWhoisCmd,
SSIZE(szWhoisCmd),
NOX(
"/WHOIS %s"), nickname);
1303 char szWhoisCmd[100];
1323 snprintf(szWhoisCmd,
SSIZE(szWhoisCmd),
NOX(
"/WHOIS %s"), nickname);
Chat_command * Currcommand
char Input_chat_buffer[MAXCHATBUFFER]
Chat_channel * Firstchannel
int Getting_user_tracker_error
int RemoveChatUser(char *nickname)
char * GetWordNum(int num, const char *l_String)
char * ChatGetString(void)
#define WSAGetLastError()
void FlushChatCommandQueue(void)
void RemoveAllChatUsers(void)
void AddChannel(char *channel, unsigned short numusers, char *topic)
#define PXO_CHAT_END_OF_MOTD_PREFIX
char * GetChannelByUser(char *nickname)
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void FlushChannelList(void)
void DisconnectFromChatServer()
const char * SendChatString(const char *line, int raw)
const char * XSTR(const char *str, int index)
GLbitfield GLuint64 timeout
Chat_command * Firstcommand
char Getting_user_channel_info_for[33]
Chat_channel * Currchannel
char User_req_tracker_id[100]
char * GetChannelList(void)
#define PXO_CHAT_MOTD_PREFIX
int Chat_server_connected
char Orignial_nick_name[33]
#define ioctlsocket(x, y, z)
GLenum GLsizei GLenum GLenum const GLvoid * data
char User_req_channel[100]
int SetNewChatChannel(char *channel)
Chat_command * GetChatCommandFromQueue(void)
int ConnectToChatServer(char *serveraddr, char *nickname, char *trackerid)
char Getting_user_tracker_info_for[33]
int Getting_user_channel_error
void AddChatCommandToQueue(int command, void *data, int len)
int AddChatUser(char *nickname)
char * GetTrackerIdByUser(char *nickname)
char * ParseIRCMessage(char *Line, int iMode)
Chat_command * GetChatCommand()