#include #include #include #include #include "global.h" #include "pm_log.h" int afk=0; int last_action_time=0; int afk_time=DEFAULT_AFK_MINUTES*60000; int afk_time_conf=DEFAULT_AFK_MINUTES; //For elconfig window char afk_message[MAX_TEXT_MESSAGE_LENGTH]={0}; char afk_title[101]; #ifdef AFK_FIX int afk_local = 0; #endif //AFK_FIX struct pm_struct pm_log; void print_return_message(void); /* forward declaration */ void free_pm_log() { int i; for(;--pm_log.ppl>=0;) { pm_log.afk_msgs[pm_log.ppl].msgs=0; free(pm_log.afk_msgs[pm_log.ppl].name); pm_log.afk_msgs[pm_log.ppl].name=NULL; for(i=pm_log.afk_msgs[pm_log.ppl].msgs;--i>=0;) { free(pm_log.afk_msgs[pm_log.ppl].messages[i]); pm_log.afk_msgs[pm_log.ppl].messages[i]=NULL; } } free(pm_log.afk_msgs); pm_log.afk_msgs=NULL; pm_log.msgs=pm_log.ppl=0; } void go_afk() { if(pm_log.ppl)free_pm_log(); LOG_TO_CONSOLE(c_green1,going_afk); if(!you_sit) { Uint8 str[4]; str[0]=SIT_DOWN; str[1]=1; my_tcp_send(my_socket,str,2); } afk++; } void go_ifk() { print_return_message(); afk=0; } void print_title(char * no, char * name, char * messages) { char * ptr = afk_title; memset(afk_title,' ',100); while(*no)*ptr++=*no++; *ptr=':'; ptr=afk_title+12; while(*name)*ptr++=*name++; *ptr=':'; ptr=afk_title+27; while(*messages)*ptr++=*messages++; *ptr++=':'; *ptr=0; } void print_return_message() { char str[65]; int m=-1; LOG_TO_CONSOLE(c_green1,not_afk); if(pm_log.ppl && pm_log.msgs) { safe_snprintf(str, sizeof(str), new_messages, pm_log.msgs); LOG_TO_CONSOLE(c_green2,str); print_title("#", afk_names, afk_messages); LOG_TO_CONSOLE(c_green2, afk_title); while(++m %s: %.*s", game_minute/60, game_minute%60, last_pm_from, len, message); #else safe_snprintf (buf, sizeof(buf), "<%1d:%02d> %s: %.*s", game_minute/60, game_minute%60, last_msg_from, strlen(mymsg), mymsg); #endif //AFK_FIX pm_log.afk_msgs[z].messages[pm_log.afk_msgs[z].msgs] = calloc (strlen (buf) + 1, sizeof (char)); safe_strncpy (pm_log.afk_msgs[z].messages[pm_log.afk_msgs[z].msgs], buf, (strlen(buf) + 1) * sizeof(char)); pm_log.afk_msgs[z].msgs++; pm_log.msgs++; } int my_namecmp(char *check) { int i=0; char username[32]; safe_strncpy(username, username_str, sizeof(username)); my_tolower(username); for(;i<20 && username[i] && check[i]==username[i];i++); if(check[i]==username[i]||((check[i]==' '||!isalpha((unsigned char)check[i])) && !username[i])) return 0; return 1; } int is_talking_about_me (const char *server_msg, int len, char everywhere) { int a=0; char msg[200]; if(len > 198) return 0; if (!everywhere && (server_msg[0] == '[' || server_msg[0] == '#')) { return 0; //Only do local chat } safe_snprintf (msg, sizeof(msg), "%.*s", len, server_msg); my_tolower (msg); while (msg[a] && msg[a] != ':' && IS_PRINT((unsigned char)msg[a])) a++; //We do need the name of ourselves... while (a < 199 && msg[a] != '\0') { if((msg[a]==' '||(IS_COLOR((unsigned char)msg[a]))) && !my_namecmp(msg+1+a)) return 1; else a++; } return 0; } void send_afk_message (const char *server_msg, int len, Uint8 channel) { Uint8 sendtext[MAX_TEXT_MESSAGE_LENGTH]={0}; if (afk_message[0] == '\0') return; if (channel == CHAT_PERSONAL || channel == CHAT_MODPM) { safe_snprintf ((char*)sendtext, sizeof(sendtext), "%c%s %s", SEND_PM, last_pm_from, afk_message); } else { int i, j; //char *name = (char *)calloc(32, sizeof (char)); char name[32]; // Copy the name. This ought to work for both local chat and // trade attempts i = j = 0; while (j < len && IS_PRINT((unsigned char)server_msg[j]) ) { name[i++] = server_msg[j]; if (server_msg[j] == ':' || server_msg[j] == ' ') break; j++; } name[i-1] = '\0'; if (have_name(name, i-1) < 0) { safe_snprintf ((char*)sendtext, sizeof(sendtext), "%c%s %s", SEND_PM, name, afk_message); #ifndef AFK_FIX add_name_to_pm_log (name, i-1); #endif //AFK_FIX } else { sendtext[0]= '\0'; sendtext[1]= '\0'; } } if (sendtext[1] != '\0') { my_tcp_send (my_socket, sendtext, strlen ((char*)&sendtext[1]) + 1); } }