void GameProcessSessionTimer(session_node *s) { if (s->game->object_id == INVALID_OBJECT) { /* timed out before credits drain means took too long picking character */ HangupSession(s); return; } /* they're in the game. First thing to check is if we haven't gotten any message in a while, even ping. If so, they are so lagged they should be hung up. */ /* dprintf("%u %u %u\n",GetTime(),s->game->game_last_message_time,ConfigInt(INACTIVE_GAME)); */ if (GetTime() - s->game->game_last_message_time > ConfigInt(INACTIVE_GAME)) { lprintf("GameProcessSessionTimer logging out ACCOUNT %i (%s) which hasn't been heard from.\n", s->account->account_id, s->account->name); HangupSession(s); return; } SetSessionTimer(s,ConfigInt(CREDIT_DRAIN_TIME)); s->account->credits -= ConfigInt(CREDIT_DRAIN_AMOUNT); if (s->game->game_state != GAME_NORMAL) return; #if 0 /* warn them when they are low */ if ((s->account->credits <= 100*ConfigInt(CREDIT_WARN1)) && (s->account->credits + ConfigInt(CREDIT_DRAIN_AMOUNT) > 100*ConfigInt(CREDIT_WARN1)) || (s->account->credits == 100*ConfigInt(CREDIT_WARN2)) && (s->account->credits + ConfigInt(CREDIT_DRAIN_AMOUNT) > 100*ConfigInt(CREDIT_WARN2))) GameWarnLowCredits(s); if (s->account->credits == 0) { /* send them an out-of-credits message */ GameClientExit(s); SetSessionState(s,STATE_SYNCHED); } #endif }
void GameProtocolParse(session_node *s,client_msg *msg) { user_node *u; int object_id; char *ptr; char password[MAX_LOGIN_PASSWORD+1],new_password[MAX_LOGIN_PASSWORD+1]; int len,index; char admin_cmd[500]; int admin_len; int dm_type; GameMessageCount((unsigned char)msg->data[0]); switch ((unsigned char)msg->data[0]) { case BP_REQ_QUIT : GameClientExit(s); SetSessionState(s,STATE_SYNCHED); break; case BP_RESYNC : // dprintf("client said it had an error\n"); GameSyncInit(s); GameSyncProcessSessionBuffer(s); break; case BP_PING : GameEchoPing(s); break; case BP_AD_SELECTED : /* they clicked on an ad; log it */ switch (msg->data[1]) { case 1: ptr = LockConfigStr(ADVERTISE_URL1); lprintf("GameProtocolParse found account %i visited ad 1, %s\n",s->account->account_id, ptr); UnlockConfigStr(); break; case 2: ptr = LockConfigStr(ADVERTISE_URL2); lprintf("GameProtocolParse found account %i visited ad 2, %s\n",s->account->account_id, ptr); UnlockConfigStr(); break; default : eprintf("GameProtocolParse found account %i visited unknown ad %i\n", s->account->account_id,msg->data[1]); } break; case BP_USE_CHARACTER : if (s->game->object_id == INVALID_OBJECT) { object_id = *((int *)(msg->data+1)); u = GetUserByObjectID(object_id); if (u != NULL && u->account_id == s->account->account_id) GameStartUser(s,u); else eprintf("GameProtocolParse can't find user for obj %i in use char!!!\n", object_id); InterfaceUpdateSession(s); } break; case BP_REQ_ADMIN : if (s->account->type != ACCOUNT_ADMIN) { eprintf("GameProtocolParse got admin command from non admin account %i\n", s->account->account_id); break; } admin_len = (int) * ((short *)(msg->data + 1)); if (admin_len > msg->len - 3) return; if (admin_len > sizeof(admin_cmd)-2) return; memcpy(admin_cmd,&msg->data[3],admin_len); admin_cmd[admin_len] = 0; SendSessionAdminText(s->session_id,"> %s\n",admin_cmd); /* echo it to 'em */ TryAdminCommand(s->session_id,admin_cmd); break; case BP_REQ_DM : if (s->account->type != ACCOUNT_ADMIN && s->account->type != ACCOUNT_DM) { eprintf("GameProtocolParse got DM command from non admin or DM account %i\n", s->account->account_id); break; } dm_type = msg->data[1]; admin_len = (int) * ((short *)(msg->data + 2)); if (admin_len > msg->len - 4) return; if (admin_len > sizeof(admin_cmd)-2) return; memcpy(admin_cmd,&msg->data[4],admin_len); admin_cmd[admin_len] = 0; GameDMCommand(s,dm_type,admin_cmd); break; case BP_SEND_CHARACTERS : GameTryGetUser(s); break; case BP_CHANGE_PASSWORD : index = 1; len = *(short *)(msg->data+index); if (index + 2 + len > msg->len) /* 2 = length word len */ break; if (len-1 > sizeof(password)) break; memcpy(password,msg->data+index+2,len); password[len] = 0; /* null terminate string */ index += 2 + len; len = *(short *)(msg->data+index); if (index + 2 + len > msg->len) break; if (len-1 > sizeof(new_password)) break; memcpy(new_password,msg->data+index+2,len); new_password[len] = 0; /* null terminate string */ index += 2 + len; if (strcmp(s->account->password,password)) { AddByteToPacket(BP_PASSWORD_NOT_OK); SendPacket(s->session_id); break; } SetAccountPasswordAlreadyEncrypted(s->account,new_password); AddByteToPacket(BP_PASSWORD_OK); SendPacket(s->session_id); break; default : ClientToBlakodUser(s,msg->len,msg->data); break; } }