/* Sends the player the actions he must do. Usefull as callback */ STATIC TEG_STATUS token_loque( int fd, char *unused ) { PSPLAYER pJ; PLAY_DEBUG("token_loque()"); if( player_whoisfd( fd, &pJ ) != TEG_STATUS_SUCCESS ) { goto error; } switch( pJ->estado ) { case PLAYER_STATUS_FICHAS: net_printf( fd, "%s=%d,%d\n", TOKEN_FICHAS, g_game.turno->numjug,g_game.fichas); break; case PLAYER_STATUS_FICHAS2: net_printf( fd, "%s=%d,%d\n", TOKEN_FICHAS2, g_game.turno->numjug,g_game.fichas); break; case PLAYER_STATUS_FICHASC: case PLAYER_STATUS_CANJE: aux_token_fichasc( g_game.turno ); break; case PLAYER_STATUS_ATAQUE: case PLAYER_STATUS_TROPAS: net_printf( fd, "%s=%d\n", TOKEN_TURNO, g_game.turno->numjug ); break; default: break; } return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_LOQUE"\n"); return TEG_STATUS_PARSEERROR; }
void mcsdb_client_set (McSdbClient *ms, const char *key, const char *body, ut64 exptime __unused) { net_printf (ms->fd, "set %s 0 0 %d\r\n", key, strlen (body)); net_flush (ms->fd); net_printf (ms->fd, "%s\r\n", body); net_flush (ms->fd); free (net_readnl (ms->fd)); }
/** * @fn TEG_STATUS fichas_out() * Envia las fichas al server. Usada por FICHAS, FICHAS2 y FICHASC */ TEG_STATUS fichas_out() { char buf[2000]; char tmp[100]; int *ptr; int i; int first_time; PLAYER_STATUS e; if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg( M_ERR,_("Error, its not the time to send armies")); return TEG_STATUS_ERROR; } if( fichas_finish( &ptr ) != TEG_STATUS_SUCCESS ) { fichas_reset(); textmsg( M_ERR,_("Error, put the correct number of armies")); return TEG_STATUS_ERROR; } buf[0]=0; tmp[0]=0; first_time = 1; for(i=0;i<COUNTRIES_CANT;i++) { if( ptr[i]>0 ) { if( first_time ) sprintf(tmp,"%d:%d",i,ptr[i]); else sprintf(tmp,",%d:%d",i,ptr[i]); strcat(buf,tmp); first_time = 0; } } e = ESTADO_GET(); switch(e) { case PLAYER_STATUS_FICHAS: net_printf(g_game.fd,TOKEN_FICHAS"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHAS); break; case PLAYER_STATUS_FICHAS2: net_printf(g_game.fd,TOKEN_FICHAS2"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHAS2); break; case PLAYER_STATUS_FICHASC: net_printf(g_game.fd,TOKEN_FICHASC"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHASC); break; default: textmsg( M_ERR,_("Error, its not the moment to send your armies")); return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/*Sends the protocol version, request the server version, send the client version */ TEG_STATUS out_pversion() { if( g_game.fd > 0 ) { net_printf(g_game.fd,TOKEN_PVERSION"=%d,%d\n",PROTOCOL_HIVER,PROTOCOL_LOVER); net_printf(g_game.fd,TOKEN_SVERSION"\n"); out_cversion(); } return TEG_STATUS_SUCCESS; }
int CreateMailSocket() /* open socket to mail server */ { int ms; char buffer[256]; ms = ConnectServer(MAILSERVER, SMTPPORT); if (ms < 0) ms = ConnectServer("127.0.0.1", SMTPPORT); if (ms > 0) { while (net_gets(ms, buffer, sizeof(buffer))) { if (strncmp(buffer, "220-", 4)) break; } if (strncmp(buffer, "220 ", 4)) { CloseMailSocket(ms); return -1; } net_printf(ms, "HELO bbs\r\n"); while (net_gets(ms, buffer, sizeof(buffer))) { if (strncmp(buffer, "250-", 4)) break; } if (strncmp(buffer, "250 ", 4)) { CloseMailSocket(ms); return -1; } } return ms; }
/* request the server the type of game */ TEG_STATUS out_status() { if( ESTADO_MENOR(PLAYER_STATUS_CONNECTED) ) return TEG_STATUS_NOTCONNECTED; net_printf(g_game.fd,TOKEN_STATUS"\n"); return TEG_STATUS_SUCCESS; }
/* Callback for GGZDMOD_EVENT_STATE */ static void _handle_ggz_state(GGZdMod *ggz, GGZdModEvent event, const void *data) { switch(ggzdmod_get_state(ggz)) { case GGZDMOD_STATE_PLAYING: break; case GGZDMOD_STATE_WAITING: { GGZSeat seat; int i; int robot_socket; int max = ggzdmod_get_num_seats( g_ggzdmod ); // launch robots if necesary for (i = 0; i < max; i++) { seat = ggzdmod_get_seat( g_ggzdmod, i ); if( seat.type == GGZ_SEAT_BOT ) { if (launch_robot( &robot_socket, "--ggz" ) == TEG_STATUS_SUCCESS ) { seat.fd = robot_socket; ggzdmod_set_seat( g_ggzdmod, &seat ); net_printf(seat.fd,"%s=1\n",TOKEN_GGZ); } else ggzdmod_log(g_ggzdmod, "\tegserver: Failed launching bot :-(!"); } } break; } case GGZDMOD_STATE_DONE: break; default: break; } }
/* Server version */ STATIC TEG_STATUS token_sversion( int fd, char *unused ) { PLAY_DEBUG("token_sversion()\n"); net_printf(fd,"%s=%s %s\n", TOKEN_SVERSION, _("TEG server version "),VERSION); return TEG_STATUS_SUCCESS; }
static int dowhoall(int fd) { char buf[100]; char *chatid, *userid, *channame; printchatline(_msg_chat_10); sprintf(genbuf, "[7m%-10s %-12s %-15s[m", _msg_chat_8, _msg_chat_9, _msg_chat_11); printchatline(genbuf); sprintf(genbuf, "%-10s %-12s %-15s", "------", "------", "------"); printchatline(genbuf); net_printf(fd, "WHOALL\r\n"); net_gets(fd, genbuf, sizeof(genbuf)); if (strncmp(genbuf, "+OK", 3)) return -1; do { net_gets(fd, buf, sizeof(buf)); if (buf[0] == '.') break; userid = strtok(buf, "\t"); chatid = strtok(NULL, "\t\r\n"); channame = strtok(NULL, "\t\r\n"); sprintf(genbuf, "%-10s %-12s %-15s", chatid, userid, channame); printchatline(genbuf); } while (buf[0] != '.'); return 0; }
static int dolist(int fd) { char buf[80]; char channame[80], topic[80], op[80], members[80], secret[80]; printchatline(_msg_chat_16); sprintf(buf, "%-15s %-20s %-12s %-6s %-4s", _msg_chat_17, _msg_chat_18, _msg_chat_19, _msg_chat_20, _msg_chat_21); printchatline(buf); sprintf(buf, "%-15s %-20s %-12s %-6s %-4s", "------", "------", "------", "------", "------"); printchatline(buf); net_printf(fd, "LISTCHAN\r\n"); net_gets(fd, genbuf, sizeof(genbuf)); if (strncmp(genbuf, "+OK", 3)) return -1; do { net_gets(fd, buf, sizeof(buf)); if (buf[0] == '.') break; sscanf(buf, "%s\t%s\t%s\t%s\t%s\r\n", channame, topic, op, members, secret); sprintf(genbuf, "%-15s %-20s %-12s %-6s %-4s", channame, topic, op, members, secret); printchatline(genbuf); } while (buf[0] != '.'); return 0; }
/* sends client version */ TEG_STATUS out_cversion() { if( g_game.fd > 0 ) net_printf(g_game.fd,TOKEN_CVERSION"=%s %s\n",_("TEG client version "),VERSION); return TEG_STATUS_SUCCESS; }
/* tell the server which color I prefer */ TEG_STATUS out_color( int color ) { if( ESTADO_MAYOR_IGUAL(PLAYER_STATUS_HABILITADO) ) return TEG_STATUS_ERROR; net_printf( g_game.fd, TOKEN_COLOR"=%d\n", color ); return TEG_STATUS_SUCCESS; }
/* start the game */ TEG_STATUS out_start() { if( ESTADO_ES(PLAYER_STATUS_HABILITADO) ) { net_printf(g_game.fd,TOKEN_START"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_NOTCONNECTED; }
/* Ask for a card after the attack */ STATIC TEG_STATUS token_card( int fd, char *str ) { PSPLAYER pJ; PCOUNTRY pP; PLAY_DEBUG("token_card()\n"); /* Veo si puede sacar una tarjeta... */ if( player_whoisfd( fd, &pJ ) != TEG_STATUS_SUCCESS ) goto error; if( pJ->estado < PLAYER_STATUS_TURNOSTART || pJ->estado >= PLAYER_STATUS_TARJETA) goto error; // player may not have more than TEG_MAX_TARJETAS cards if( pJ->tot_cards >= TEG_MAX_TARJETAS ) goto error; // must have conquered a country to get a card if( pJ->turno_conq < 1 ) goto error; // after the 3rd exchange, the player must have conquered two countries if( pJ->tot_exchanges > 3 && pJ->turno_conq < 2 ) goto error; /* Puede sacar tarjeta */ pJ->tot_cards++; pP = get_random_country( tarjeta_es_libre ); pJ->estado = PLAYER_STATUS_TARJETA; tarjeta_sacar( &pP->tarjeta, pJ->numjug ); /* * Me fijo si el player es due�o del pa�s que dice la tarjeta. Si es as� * le agrego 2 fichas automaticamente como dice el reglamento. * Check if the card that the player gets is for a country that this player * owns. If yes, automatically place two armies according to the rules. */ if( pP->numjug == pJ->numjug ) { pP->ejercitos += 2; pJ->tot_armies += 2; tarjeta_usar( &pP->tarjeta ); if( ! g_game.fog_of_war ) netall_printf( "%s=%d,%d,%d\n", TOKEN_COUNTRY,pP->id,pP->numjug,pP->ejercitos); else fow_netall_printf( pP->id, "%s=%d,%d,%d\n", TOKEN_COUNTRY,pP->id,pP->numjug,pP->ejercitos); } net_printf(fd,"%s=%d,%d\n", TOKEN_TARJETA, pP->id,pP->tarjeta.usada); return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_TARJETA"\n"); return TEG_STATUS_ERROR; }
/* Callback for GGZDMOD_EVENT_SPECTATOR_JOIN */ static void _handle_ggz_spectator_join(GGZdMod *ggz, GGZdModEvent event, const void *data) { GGZSpectator s; s = ggzdmod_get_spectator( ggz, *(int*) data ); /* fprintf( stderr, "new spectator in fd: %d-%s (%d)\n",s.fd,s.name, *(int*) data ); */ net_printf(s.fd,"%s=0\n", TOKEN_GGZ); }
/* tells the server who am i */ TEG_STATUS out_id() { if( ESTADO_MAYOR_IGUAL(PLAYER_STATUS_CONNECTED ) ) return TEG_STATUS_ERROR; strip_invalid(g_game.myname); net_printf( g_game.fd, TOKEN_PLAYERID"=%s,%d,%d\n", g_game.myname, !g_game.observer, g_game.human ); return TEG_STATUS_SUCCESS; }
/* sends message to all players (via server) */ TEG_STATUS out_mensaje( char *msg ) { if( ESTADO_MENOR(PLAYER_STATUS_CONNECTED) ) return TEG_STATUS_NOTCONNECTED; strip_invalid_msg(msg); net_printf( g_game.fd, TOKEN_MESSAGE"=\"%s\"\n",msg); return TEG_STATUS_SUCCESS; }
void meta_start_game(void) { #ifdef CLOSE_META_AT_START if (ses != NULL) { net_printf(ses, "begin\n"); net_free(&ses); } #endif }
TEG_STATUS option_help( int fd, char *str ) { int i; for(i=0;i<NOPTIONS;i++) { if(options[i].func) net_printf(fd, TOKEN_REM"='%s' %s\n",options[i].label,_(options[i].help)); } return TEG_STATUS_SUCCESS; }
/* Ask for help */ STATIC TEG_STATUS token_help ( int fd, char *unused ) { int i; for(i=0;i<NTOKENS;i++) { if(tokens[i].func) net_printf(fd, "%s='%s' %s\n", TOKEN_REM, tokens[i].label,_(tokens[i].help)); } return TEG_STATUS_SUCCESS; }
int CloseMailSocket(int ms) /* close socket to mail server */ { char buffer[STRLEN]; net_printf(ms, "QUIT\r\n"); net_gets(ms, buffer, sizeof(buffer)); close(ms); return 0; }
/* Sends to server a request for a 'get card' */ TEG_STATUS out_tarjeta() { if( ESTADO_MENOR(PLAYER_STATUS_ATAQUE) || ESTADO_MAYOR_IGUAL(PLAYER_STATUS_TARJETA) ) { textmsg( M_ERR,_("Error, it's not the moment to get a card")); return TEG_STATUS_ERROR; } net_printf(g_game.fd,TOKEN_TARJETA"\n"); return TEG_STATUS_SUCCESS; }
/* ask for scores */ TEG_STATUS out_scores() { PLAYER_STATUS e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED && g_game.fd > 0 ) { net_printf(g_game.fd,TOKEN_SCORES"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* request a robot */ TEG_STATUS out_robot() { PLAYER_STATUS e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED && e < PLAYER_STATUS_START && g_game.fd > 0 ) { net_printf(g_game.fd,TOKEN_ROBOT"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* tells the server that I surrender */ TEG_STATUS out_surrender() { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_START ) { net_printf(g_game.fd,TOKEN_SURRENDER"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* ask server what do I have to do (robots uses this) */ TEG_STATUS out_loque( void ) { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED ) { net_printf(g_game.fd,TOKEN_LOQUE"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* echo client (robots uses this) */ TEG_STATUS out_echo( char *msg ) { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED ) { net_printf(g_game.fd,TOKEN_ECHO"=%s\n",msg); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* ask server the countries' status */ TEG_STATUS out_countries() { if( ESTADO_MENOR(PLAYER_STATUS_CONNECTED) ) { textmsg( M_ERR,_("Error, you must be connected")); return TEG_STATUS_NOTCONNECTED; } net_printf(g_game.fd,TOKEN_COUNTRIES"=-1\n"); return TEG_STATUS_SUCCESS; }
TEG_STATUS out_enum_cards() { if( ESTADO_MENOR(PLAYER_STATUS_CONNECTED) ) { textmsg( M_ERR,_("Error, you must be connected")); return TEG_STATUS_NOTCONNECTED; } net_printf(g_game.fd,TOKEN_ENUM_CARDS"\n"); return TEG_STATUS_SUCCESS; }
TEG_STATUS out_new_round() { if( ESTADO_MENOR(PLAYER_STATUS_CONNECTED) ) { textmsg( M_ERR,_("Error, you must be connected")); return TEG_STATUS_NOTCONNECTED; } net_printf(g_game.fd,TOKEN_NEW_ROUND"\n"); return TEG_STATUS_SUCCESS; }