void GameTryGetUser(session_node *s) { char *ptr; if (0 && s->account->type == ACCOUNT_GUEST) /* let guests choose too */ { GameStartUser(s,GetFirstUserByAccountID(s->account->account_id)); } else { AddByteToPacket(BP_CHARACTERS); AddShortToPacket((short)CountUserByAccountID(s->account->account_id)); ForEachUserByAccountID(GameSendEachUserChoice,s->account->account_id); AddStringToPacket(GetMotdLength(),GetMotd()); /* advertising stuff */ AddByteToPacket(2); ptr = LockConfigStr(ADVERTISE_FILE1); AddStringToPacket(strlen(ptr),ptr); UnlockConfigStr(); ptr = LockConfigStr(ADVERTISE_URL1); AddStringToPacket(strlen(ptr),ptr); UnlockConfigStr(); ptr = LockConfigStr(ADVERTISE_FILE2); AddStringToPacket(strlen(ptr),ptr); UnlockConfigStr(); ptr = LockConfigStr(ADVERTISE_URL2); AddStringToPacket(strlen(ptr),ptr); UnlockConfigStr(); SendPacket(s->session_id); } }
void UpdateSecurityRedbook() { // Okay, timing is important here: // The _redbookstring must be updated to any new value // before we call GameEchoPing() on any sessions, but the // current strings held by any of the sessions now must // remain valid so the GameEchoPing() output doesn't access // a freed old string. // // We remember the old string for comparisons and for freeing last. // We get the new resource. // We update _redbookstring and _redbookid. // We see if users need an update at all. // We free the string which sessions were using AFTER the GameEchoPing. // char* pRscName; char* old; resource_node* r = NULL; old = _redbookstring; _redbookstring = NULL; _redbookid = 0; pRscName = LockConfigStr(SECURITY_REDBOOK_RSC); if (pRscName) r = GetResourceByName(pRscName); UnlockConfigStr(); if (r) { if (!old || (r->resource_val && 0 != strcmp(old,r->resource_val))) _redbookstring = strdup(r->resource_val); else _redbookstring = old; _redbookid = r->resource_id; } if (old != _redbookstring) { ForEachSession(GameEchoPing); if (old) free(old); } }
/* GetLocalMachineName Return value is valid only temporarily. NOT THREAD SAFE */ char *GetLocalMachineName(void) { static char name[200],full_name[200]; struct hostent *site_data; strcpy(full_name,LockConfigStr(EMAIL_LOCAL_MACHINE_NAME)); UnlockConfigStr(); return full_name; if (gethostname(name,sizeof(name)) == SOCKET_ERROR) strcpy(name,"localhost"); site_data = NULL; site_data = gethostbyname(name); if (site_data != NULL) strcpy(full_name,site_data->h_name); else strcpy(full_name,"localhost"); return full_name; }
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; } }