/************************************************************************** Called when the return key is pressed. **************************************************************************/ static void inputline_return(GtkEntry *w, gpointer data) { const char *theinput; theinput = gtk_entry_get_text(w); if (*theinput) { if (client_state() == C_S_RUNNING && gui_gtk2_allied_chat_only && is_plain_public_message(theinput)) { char buf[MAX_LEN_MSG]; fc_snprintf(buf, sizeof(buf), ". %s", theinput); send_chat(buf); } else { send_chat(theinput); } if (genlist_size(history_list) >= MAX_CHATLINE_HISTORY) { void *data; data = genlist_get(history_list, -1); genlist_remove(history_list, data); free(data); } genlist_prepend(history_list, fc_strdup(theinput)); history_pos=-1; } gtk_entry_set_text(w, ""); }
/** * Process a chat message or command * * @remarks Scope: private * * @param player Player List player pointer * @param message Chat message */ void process_chat(struct PL_entry *player, bstring message) { if (message->data[0] == '/') { LOG(LOG_INFO, "Command: %s", message->data); send_directchat(player, message); // TODO: temporary who cmd bstring whocmd = bfromcstr("/who"); bstring lcmd = bfromcstr("/login"); if (binstrr(message, (whocmd->slen), whocmd) != BSTR_ERR) { pthread_rwlock_rdlock(&PL_rwlock); bstring whomsg = bformat("There are %d players online", PL_count); send_directchat(player, whomsg); pthread_rwlock_unlock(&PL_rwlock); bstrFree(whomsg); } else if(binstrr(message, (lcmd->slen), lcmd) != BSTR_ERR) { send_loginresp(player); } } else { send_chat(player, message); } }
static PyObject* python_send_chat(PyObject* self, PyObject* args) { char* arg_msg; if(PyArg_ParseTuple(args, "s", &arg_msg) == 0) return NULL; send_chat(arg_msg); return Py_BuildValue("i", 0); }
// non-error-checking version int tell_chat(int cnID,int coID,int staffmode,char *format,...) { int ret; char buf[512]; va_list args; sprintf(buf,"%010u:%010u:",coID,cnID); va_start(args,format); vsnprintf(buf+22,300,format,args); va_end(args); if (staffmode) ret=send_chat(1030,buf); else ret=send_chat(1024,buf); return ret; }
/************************************************************************** Called by the GUI code when the user sets the ruleset. The ruleset passed in here should match one of the strings given to gui_set_rulesets. **************************************************************************/ void set_ruleset(const char *ruleset) { char buf[4096]; fc_snprintf(buf, sizeof(buf), "/read %s%s", ruleset, RULESET_SUFFIX); log_debug("Executing '%s'", buf); send_chat(buf); }
/**************************************************************** send server command to save game. *****************************************************************/ void send_save_game(const char *filename) { if (filename) { send_chat_printf("/save %s", filename); } else { send_chat("/save"); } }
/************************************************************************** Called by the GUI code when the user sets the ruleset. The ruleset passed in here should match one of the strings given to gui_set_rulesets. **************************************************************************/ void set_ruleset(const char *ruleset) { char buf[4096]; my_snprintf(buf, sizeof(buf), "/read %s%s", ruleset, RULESET_SUFFIX); freelog(LOG_DEBUG, "Executing '%s'", buf); send_chat(buf); }
void net_send_chat (char *text, signed char notigamesrv) { int i; for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i)) send_chat (&players[i].net.addr, text); };
int server_chat(int channel,char *text) { if (strlen(text)>200) { return 0; } send_chat(channel,text); return 1; }
/************************************************************************** Handles WM_COMMAND messages from the chatline To find out when the return key is pressed, it checks for newlines in the string A backup of the string (without the newline) is sent to the server Is there a nicer way to handle this? **************************************************************************/ void handle_chatline(void) { static char msg_buf[MAX_LEN_MSG-MAX_LEN_USERNAME+1]; char msg_buf2[MAX_LEN_MSG-MAX_LEN_USERNAME+1]; GetWindowText(hchatline,msg_buf2,sizeof(msg_buf2)); if (strchr(msg_buf2,'\n')) { send_chat(msg_buf); SetWindowText(hchatline,""); } else { sz_strlcpy(msg_buf, msg_buf2); } }
/************************************************************************** ... **************************************************************************/ void chatline_key_send(Widget w) { String theinput; String empty=""; XtVaGetValues(w, XtNstring, &theinput, NULL); if(*theinput) { send_chat(theinput); } XtVaSetValues(w, XtNstring, empty, NULL); }
/**************************************************************************** Kills the server if the client has started it. If the 'force' parameter is unset, we just do a /quit. If it's set, then we'll send a signal to the server to kill it (use this when the socket is disconnected already). ****************************************************************************/ void client_kill_server(bool force) { if (is_server_running()) { if (client.conn.used && client_has_hack) { /* This does a "soft" shutdown of the server by sending a /quit. * * This is useful when closing the client or disconnecting because it * doesn't kill the server prematurely. In particular, killing the * server in the middle of a save can have disastrous results. This * method tells the server to quit on its own. This is safer from a * game perspective, but more dangerous because if the kill fails the * server will be left running. * * Another potential problem is because this function is called atexit * it could potentially be called when we're connected to an unowned * server. In this case we don't want to kill it. */ send_chat("/quit"); #ifdef WIN32_NATIVE server_process = INVALID_HANDLE_VALUE; loghandle = INVALID_HANDLE_VALUE; #else server_pid = -1; #endif } else if (force) { /* Either we already disconnected, or we didn't get control of the * server. In either case, the only thing to do is a "hard" kill of * the server. */ #ifdef WIN32_NATIVE TerminateProcess(server_process, 0); CloseHandle(server_process); if (loghandle != INVALID_HANDLE_VALUE) { CloseHandle(loghandle); } server_process = INVALID_HANDLE_VALUE; loghandle = INVALID_HANDLE_VALUE; #elif HAVE_WORKING_FORK kill(server_pid, SIGTERM); waitpid(server_pid, NULL, WUNTRACED); server_pid = -1; #endif /* WIN32_NATIVE || HAVE_WORKING_FORK */ } } client_has_hack = FALSE; }
static int write_chat(int cn,int channel,char *text) { int bit,n,xID,col; char buf[256],name[80]; while (isspace(*text)) text++; if (!*text) { log_char(cn,LOG_SYSTEM,0,"You cannot send empty chat messages."); return 1; } if (strlen(text)>200) { log_char(cn,LOG_SYSTEM,0,"This chat message is too long."); return 1; } if ((ch[cn].flags&CF_PLAYER) && (channel==0 || channel==32) && !(ch[cn].flags&CF_GOD)) { log_char(cn,LOG_SYSTEM,0,"Access denied."); return 1; } if ((ch[cn].flags&CF_PLAYER) && channel==31 && !(ch[cn].flags&(CF_STAFF|CF_GOD))) { log_char(cn,LOG_SYSTEM,0,"Access denied."); return 1; } if ((ch[cn].flags&CF_PLAYER) && channel) { bit=1<<(channel-1); if (!(ch[cn].channel&bit)) { log_char(cn,LOG_SYSTEM,0,"You must join a channel before you can use it."); return 1; } } if ((ch[cn].flags&CF_PLAYER) && (channel==7 || channel==12) && get_char_clan(cn)==0) { log_char(cn,LOG_SYSTEM,0,"Access denied - clan members only."); return 1; } if ((ch[cn].flags&CF_PLAYER) && (channel==13) && get_char_club(cn)==0) { log_char(cn,LOG_SYSTEM,0,"Access denied - club members only."); return 1; } if (swearing(cn,text)) return 1; if (ch[cn].flags&CF_PLAYER) dlog(cn,0,"chat(%s): \"%s\"",cname[channel].name,text); if (ch[cn].flags&CF_STAFF) { for (n=0; n<75 && ch[cn].name[n]; n++) name[n]=toupper(ch[cn].name[n]); name[n]=0; } else strcpy(name,ch[cn].name); if (ch[cn].flags&(CF_STAFF|CF_GOD)) xID=0; else xID=ch[cn].ID; switch(channel) { case 0: col=3; break; // announce case 1: col=12; break; // info case 2: col=2; break; // gossipe case 3: col=9; break; // auction case 4: col=14; break; // v2 case 5: col=15; break; // public clan case 6: col=10; break; // grats case 7: col=16; break; // internal clan case 8: col=13; break; // area case 9: col=11; break; // mirror case 10: col=14; break; // games case 11: col=14; break; // kill case 12: col=16; break; // allied clan case 13: col=16; break; // club channel case 31: col=7; break; // staff case 32: col=8; break; // god default: col=2; break; } if (channel==0) sprintf(buf,"°c%d%s",col,text); // announce else if (channel==7 || channel==12) sprintf(buf,"%010u:%02u:°c%d%s: °c17%s°c18 (%d) says: \"%s\"",xID,get_char_clan(cn),col,cname[channel].name,name,ch[cn].mirror,text); // clan internal else if (channel==13) sprintf(buf,"%010u:%02u:°c%d%s: °c17%s°c18 (%d) says: \"%s\"",xID,get_char_club(cn),col,cname[channel].name,name,ch[cn].mirror,text); // club internal else if (channel==8) { sprintf(buf,"%010u:%02u:°c%d%s: °c17%s°c18%s%s%s (%d) says: \"%s\"", xID, areaID, col, cname[channel].name, name, (ch[cn].flags&CF_STAFF) ? " [" : "", (ch[cn].flags&CF_STAFF) ? ch[cn].staff_code : "", (ch[cn].flags&CF_STAFF) ? "]" : "", ch[cn].mirror, text); // area internal } else if (channel==9) { sprintf(buf,"%010u:%02u:%02u:°c%d%s: °c17%s°c18%s%s%s (%d) says: \"%s\"", xID, areaID, areaM, col, cname[channel].name, name, (ch[cn].flags&CF_STAFF) ? " [" : "", (ch[cn].flags&CF_STAFF) ? ch[cn].staff_code : "", (ch[cn].flags&CF_STAFF) ? "]" : "", ch[cn].mirror, text); // mirror internal } else if (channel==4) { sprintf(buf,"%010u°c%d%s: °c17%s°c18%s%s%s (%s) says: \"%s\"", xID, col, cname[channel].name, name, (ch[cn].flags&CF_STAFF) ? " [" : "", (ch[cn].flags&CF_STAFF) ? ch[cn].staff_code : "", (ch[cn].flags&CF_STAFF) ? "]" : "", "OW", text); // normal } else { sprintf(buf,"%010u°c%d%s: °c17%s°c18%s%s%s (%d) says: \"%s\"", xID, col, cname[channel].name, name, (ch[cn].flags&CF_STAFF) ? " [" : "", (ch[cn].flags&CF_STAFF) ? ch[cn].staff_code : "", (ch[cn].flags&CF_STAFF) ? "]" : "", ch[cn].mirror, text); // normal } send_chat(channel,buf); return 1; }
/**************************************************************** send server commands to start a saved game. *****************************************************************/ void send_start_saved_game(void) { send_chat("/set timeout 0"); send_chat_printf("/take \"%s\" \"%s\"", user_name, leader_name); send_chat("/start"); }