void kaillera_user_join_callback(char*name, int ping, unsigned short id, char conn){ kaillera_ui_trace("kaillera_user_join_callback(name=%s, ping=%d, id=%d, conn=%d)", name, ping, id, conn); kaillera_user_add_callback(name, ping, 1, id, conn); kaillera_ui_debug("* Joins: %s; ping = %i", name, ping); // TODO: sort user list }
void kaillera_ProcessGeneralInstruction(k_instruction * ki) { switch (ki->type) { case USERJOIN: // user joins the server { unsigned short id = ki->load_short(); int ping = ki->load_int(); int conn = ki->load_char(); kaillera_user_join_callback(ki->user, ping, id, conn); break; } case USERLEAV: { unsigned short id = ki->load_short(); char quitmsg[128]; ki->load_str(quitmsg, 128); kaillera_user_leave_callback(ki->user, quitmsg, id); break; } case GAMEMAKE: { //kaillera_core_debug("GAMEMAKE"); char gname[128]; ki->load_str(gname, 128); char emulator[128]; ki->load_str(emulator, 128); unsigned int id = ki->load_int(); kaillera_game_create_callback(gname, id, emulator, ki->user); if (KAILLERAC.game_id_requested) { KAILLERAC.game_id = id; if (strcmp(gname, KAILLERAC.GAME)==0 && strcmp(emulator, KAILLERAC.APP)==0 && strcmp(ki->user, KAILLERAC.USERNAME)==0) { KAILLERAC.game_id_requested = false; KAILLERAC.user_id_requested = true; KAILLERAC.USERSTAT = 3; KAILLERAC.PLAYERSTAT = 0; kaillera_user_game_create_callback(); } } break; } case INSTRUCTION_GAMESTAT: { unsigned int id = ki->load_int(); char status = ki->load_char(); int players = ki->load_char(); int maxplayers = ki->load_char(); kaillera_game_status_change_callback(id, status, players, maxplayers); break; } case INSTRUCTION_GAMESHUT: { unsigned int id = ki->load_int(); kaillera_game_close_callback(id); if (id==KAILLERAC.game_id){ kaillera_user_game_closed_callback(); kaillera_end_game_callback(); KAILLERAC.USERSTAT = 2; KAILLERAC.PLAYERSTAT = -1; } break; } case GAMEBEGN: { //kaillera_core_debug("GAMEBEGN"); //KAILLERAC.USERSTAT = 3; KAILLERAC.PLAYERSTAT = 1; KAILLERAC.throughput = ki->load_short(); KAILLERAC.dframeno = (KAILLERAC.throughput + 1) * KAILLERAC.conset - 1; KAILLERAC.playerno = ki->load_char(); int players = ki->load_char(); kaillera_game_callback(0, KAILLERAC.playerno, players); kaillera_core_debug("Server says: delay is %i frames", KAILLERAC.dframeno); break; } case GAMRSLST: { //kaillera_core_debug("GAMRSLST"); if (!KAILLERAC.owner) kaillera_user_game_joined_callback(); KAILLERAC.USERSTAT = 3; KAILLERAC.PLAYERSTAT = 0; int numplayers = ki->load_int(); for (int x=0; x < numplayers; x++) { char name[32]; ki->load_str(name, 32); int ping = ki->load_int(); unsigned short id = ki->load_short(); int conn = ki->load_char(); kaillera_player_add_callback(name, ping, id, conn); } break; } case GAMRJOIN: { //kaillera_core_debug("GAMRJOIN"); ki->load_int(); char username[32]; ki->load_str(username, 32); int ping = ki->load_int(); unsigned short uid = ki->load_short(); char connset = ki->load_char(); kaillera_player_joined_callback(username, ping, uid, connset); if (KAILLERAC.user_id_requested) { KAILLERAC.user_id = uid; if (KAILLERAC.conset == connset && strcmp(username, KAILLERAC.USERNAME)==0) { KAILLERAC.user_id_requested = false; KAILLERAC.USERSTAT = 3; KAILLERAC.PLAYERSTAT = 0; } } break; } case GAMRLEAV: { unsigned short id; kaillera_player_left_callback(ki->user, id = ki->load_short()); if (id==KAILLERAC.user_id && !KAILLERAC.leave_game_requested) { kaillera_user_kicked_callback(); KAILLERAC.USERSTAT = 2; KAILLERAC.PLAYERSTAT = -1; } break; } case GAMRDROP: { int gdpl = ki->load_char(); if (KAILLERAC.playerno == gdpl) { KAILLERAC.USERSTAT = 3; KAILLERAC.PLAYERSTAT = 0; kaillera_end_game_callback(); } kaillera_player_dropped_callback(ki->user, gdpl); break; } case PARTCHAT: { kaillera_chat_callback(ki->user, ki->buffer); } break; case GAMECHAT: { kaillera_game_chat_callback(ki->user, ki->buffer); } break; case MOTDLINE: kaillera_motd_callback(ki->user, ki->buffer); break; case LONGSUCC: { KAILLERAC.USERSTAT = KAILLERAC.USERSTAT == 1? 2:KAILLERAC.USERSTAT; int gameZ; int userZ; userZ = ki->load_int(); gameZ = ki->load_int(); int x; //users for(x=0;x<userZ; x++) { char name[32]; ki->load_str(name, 32); int ping = ki->load_int(); int status = ki->load_char(); unsigned short id = ki->load_short(); int conn = ki->load_char(); kaillera_user_add_callback(name, ping, status, id, conn); } for(x=0;x<gameZ; x++) { char gname[128]; ki->load_str(gname, 128); unsigned int id = ki->load_int(); char emulator[128]; ki->load_str(emulator, 128); char owner[32]; ki->load_str(owner, 32); char users[20]; ki->load_str(users, 20); int status = ki->load_char(); kaillera_game_add_callback(gname, id, emulator, owner, users, status); } KAILLERAC.tmoutrsttime = p2p_GetTime(); break; } case SERVPING: { if(!spoofing) // norma pong response only if not spoofing SendPong(); break; } case LOGNSTAT: { ki->load_short(); char lsmsg[128]; ki->load_str(lsmsg, 128); kaillera_login_stat_callback(lsmsg); break; } default: return; } }