// *************************************************************** // Function: AdminConsole.h // *************************************************************** #pragma once #include #include "Main.h" #include "LocalData.h" #include "GameServerData.h" int Shutdown(); //Clean-up the server void Restart(); #ifdef WIN32 using namespace stdext; #endif struct AdminList { short networkId; bool authenticated; unsigned char accessLevel; int (*QueryProcess)(QUERY_RESULT* pResult, AdminList* pAl); unsigned long queryId; void* pTempData; unsigned char passHash[32]; unsigned char accName[100]; unsigned long accountId; short forwardToGs; }; extern hash_map gAdmins; unsigned long admin_auth_code=0; #define Send_Response(compPacket) SendResponse(&compPacket, pAl->networkId, gpInternalComm) #define Send_Term() SendTerminator(pAl) //************************************ // Name: SendResponse // // Sends a command response to the admin console client. // // Parameters: // pPck - Command data byte buffer // networkId - Client network id // pNetServer - Network server to use // // Return: // //************************************ void SendResponse(CompiledPacket* pPck, short networkId, Server* pNetServer) { CompiledPacket pck2; pck2.AddByte(AC_COMMAND); int ds; unsigned char *data=pPck->GetString(&ds); pck2.AddByte(ds); pck2.Add(data, ds, false); pPck->Clear(); Util::SendCompiledPacket(&pck2, networkId, pNetServer); } //************************************ // Name: SendTerminator // // Sends the command termination packet to the admin console client. // // Parameters: // pAl - Admin client data // // Return: // //************************************ void SendTerminator(AdminList* pAl) { CompiledPacket pck; pck.Add("TERMINATOR"); Send_Response(pck); } //************************************ // Name: ProcessACGSResponse // // If the game server sends a admin console response this function relays it to our admin console client. // // Parameters: // pData - Network data // // Return: // //************************************ void ProcessACGSResponse(NetMessage* pData) { char buf[251]; memset(buf, 0, 251); short NetID=Read_uShort(pData->pData+2); memcpy(buf, pData->pData+4, pData->dataSize-4); CompiledPacket pck; pck.Add(buf); SendResponse(&pck, NetID, gpInternalComm); } //************************************ // Name: ServerEvent // // Logs a server event in the event table in the database. // // Parameters: // AdminAccountID - The admin's account id // pEvent - The event name // pInfo - Information about the event. // pDatabase - What database to use // // Return: // //************************************ void ServerEvent(unsigned long AdminAccountID, char* pEvent, char* pInfo, void* pDatabase) { GWLPDatabase* pDb=(GWLPDatabase*)pDatabase; time_t ctime=time(NULL); char query[2500]; sprintf(query, "INSERT INTO server_events (EventTime, AuthorizedBy, ServerName, Event, Info) VALUES (%u, %u, '%s', '%s', '%s')", ctime, AdminAccountID, gServerConfig.serverName, pEvent, pInfo); pDb->Query(query, (long)strlen(query)); } #define IsCommand(command) strcmp(args[0], command)==0 //************************************ // Name: OutputKey // // Processes the access key info query when generating an invite. Compiles an invite and sends it to the admin console client. // // Parameters: // pResult - Database query result // pAl - Admin's data // // Return: // //************************************ int OutputKey(QUERY_RESULT* pResult, AdminList* pAl) { CompiledPacket pck; if (pResult->pResult==0) { pck.Add("Database error occurred."); Send_Response(pck); Send_Term(); } if (mysql_num_rows(pResult->pResult)==0) { pck.Add("No keys are available. Use /generatekey on the game server to make more."); Send_Response(pck); Send_Term(); } else { MYSQL_ROW row=mysql_fetch_row(pResult->pResult); unsigned char *pRow=(unsigned char*)row[0]; char query[150]; sprintf(query, "UPDATE access_keys SET KeyStatus=3 WHERE AccessKey=\"%s\" LIMIT 1@NOSTATUS", row[0]); gDatabase.Query(query, (unsigned long)strlen(query)); //Create the formatted key CompiledPacket pck2; pck2.Add(pRow, 5, false); pck2.Add("-"); pck2.Add(pRow+5, 5, false); pck2.Add("-"); pck2.Add(pRow+10, 5, false); pck2.Add("-"); pck2.Add(pRow+15, 5, false); pck2.Add("-"); pck2.Add(pRow+20, 5, false); int key_size=0; unsigned char* pKey_data=pck2.GetString(&key_size); //Load the invite template char temp[5000]; ifstream fin("Config/invite_template.txt"); fin.getline(temp, 5000, '$'); fin.close(); //Convert the key to a string char key[50]; memset(key, 0, 50); memcpy(key, pKey_data, key_size); //Copy the admin's email and remove the part after @ char email[100]; strcpy(email, (char*)pAl->accName); char *pAt_sign=strstr(email, "@"); if (pAt_sign!=NULL){*pAt_sign=0;} //Create the invite char invite[6000]; sprintf(invite, temp, key, email); //Send the invite pck.Add("FILEASCII invite.txt"); Send_Response(pck); for (int i=0; i<(signed)strlen(invite)+1; i+=220) { int length=((int)strlen(invite)+1)-i; if (length>220){length=220;} pck.Add((unsigned char*)invite+i, 220, false); Send_Response(pck); } pck.Add("FILEEND"); Send_Response(pck); Send_Term(); } return 0; } //************************************ // Name: ProcessACCommand // // Extracts the command from the packet and processes it. // // Parameters: // pData - Network data // pAl - Admin's data // // Return: // //************************************ void ProcessACCommand(NetMessage* pData, AdminList* pAl) { char args[6][250]; memset(args, 0, 6*250); CompiledPacket pck; char backup_buf[251]; char buf[251]; memset(buf, 0, 251); memset(backup_buf, 0, 251); memcpy(buf, pData->pData+2, pData->pData[1]); memcpy(backup_buf, pData->pData+2, pData->pData[1]); delete [] pData->pData; pData->pData=0; //Break the cmd line into arguments int num_args=0; char *pToken=strtok(buf, " "); for (unsigned int i=0; pToken!=NULL; i++) { strcpy(args[i], pToken); pToken=strtok(NULL, " "); num_args++; if (num_args>5){break;} } bool log_admin_action=true; if (IsCommand("logout")) { gpInternalComm->Kick(pData->networkId); } else if (IsCommand("help")) { if (num_args==1) { pck.Add("Syntax: help {command}"); Send_Response(pck); pck.Add("Commands: logout, gs, as, gwlist, version, serverlock, invite, stats, netstats, cputhrottle, restart, shutdown, broadcast, playerlist, kick, suspend, ban, unban, mkadmin, mkgm"); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "logout")==0) { pck.Add("Logs you out of the admin console."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "mkadmin")==0) { pck.Add("Sets the Access Level of the specified account to 100. Only 100 level admins can use this."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "mkgm")==0) { pck.Add("Makes a character a GM (Game Master) of the specified level."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "playerlist")==0) { pck.Add("Lists all the players on the server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "kick")==0) { pck.Add("Kicks the specified player from the network."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "suspend")==0) { pck.Add("Suspends the specified account."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "ban")==0) { pck.Add("Bans the specified account"); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "broadcast")==0) { pck.Add("Sends a message to every player on every game server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "restart")==0) { pck.Add("Restarts the server. All configuration is reset from config file. Requires an auth code."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "shutdown")==0) { pck.Add("Shuts down the server. Requires an auth code."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "gs")==0) { pck.Add("Routes commands to a game server of your choosing."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "gwlist")==0) { pck.Add("Lists all the game servers connected to this auth server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "as")==0) { pck.Add("Routes ALL commands to the auth server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "version")==0) { pck.Add("Displays the auth server version."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "cputhrottle")==0) { pck.Add("Toggles CPU throttling on/off."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "serverlock")==0) { pck.Add("Sets the lock state of the server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "invite")==0) { pck.Add("Generates an invite with an unused key."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "unban")==0) { pck.Add("Restores an account to normal player status."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "stats")==0) { pck.Add("Displays statistics for the auth server."); Send_Response(pck); Send_Term(); } else if (strcmp(args[1], "netstats")==0) { pck.Add("Displays network statistics for the auth server."); Send_Response(pck); Send_Term(); } else { pck.Add("Not found."); Send_Response(pck); Send_Term(); } } else if (IsCommand("invite")) { char query[150]; sprintf(query, "SELECT AccessKey FROM access_keys WHERE KeyStatus=0 LIMIT 1"); pAl->queryId=gDatabase.Query(query, (unsigned long)strlen(query)); pAl->QueryProcess=OutputKey; pck.Add("Grabbing key..."); Send_Response(pck); } else if (IsCommand("gs")) { if (num_args==1) { pck.Add("Syntax: gs "); Send_Response(pck); Send_Term(); } else { hash_map::iterator itr=gGameServers.find(atoi(args[1])); if (itr!=gGameServers.end()) { pAl->forwardToGs=atoi(args[1]); char temp[100]; sprintf(temp, "You are now routed to GS%d. Type 'as' to route back to the auth server.", atoi(args[1])); pck.Add(temp); Send_Response(pck); Send_Term(); } else { char temp[100]; sprintf(temp, "%d is not a valid Game Server ID.", atoi(args[1])); pck.Add(temp); Send_Response(pck); Send_Term(); } } } else if (IsCommand("as")) { pAl->forwardToGs=0; pck.Add("You are now routed to the auth server."); Send_Response(pck); Send_Term(); } else if (IsCommand("gwlist")) { pck.Add("\nCurrently Connected Game Servers\n\n"); //List all the game servers and some stats about them hash_map::iterator itr; for (itr=gGameServers.begin(); itr!=gGameServers.end(); itr++) { char temp[100]; //Output the game server ID# sprintf(temp, "%d ", itr->second.networkId); pck.Add(temp); //Output the IP sprintf(temp, "%d.%d.%d.%d ", itr->second.ip[0], itr->second.ip[1], itr->second.ip[2], itr->second.ip[3]); pck.Add(temp); //Output the players sprintf(temp, "%u/%u ", itr->second.currentPlayers, itr->second.maxPlayers); pck.Add(temp); //Output the server dispatch state if (itr->second.currentPlayers>=itr->second.maxPlayers){pck.Add("FULL ");} else if (itr->second.isLocked){pck.Add("LOCKED ");} else{pck.Add("OPEN ");} //Output the registration mode pck.Add(itr->second.mode); //End the line pck.Add("\n"); } if (gGameServers.size()==0) { pck.Add("No game servers connected."); } Send_Response(pck); Send_Term(); } else if (pAl->forwardToGs>0) { log_admin_action=false; //Whatever the user typed must be forwarded to the game server //[header 1b][size 1b][my netID][message] if (strlen(backup_buf)>=240) { pck.Add("Error: Command line too large."); Send_Response(pck); Send_Term(); } else { CompiledPacket pck2; pck2.AddByte(LS_ADMIN_CONSOLE_COMMAND); pck2.AddByte(2+(unsigned char)strlen(backup_buf)); pck2.AddShort(pAl->networkId); pck2.Add(backup_buf); NetMessage s; s.networkId=pAl->forwardToGs; s.pData=pck2.GetString(&s.dataSize); gpInternalComm->SendData(&s); pck2.Clear(); } } else if (IsCommand("broadcast")) { if (num_args==1) { pck.Add("Syntax: broadcast {message}"); Send_Response(pck); Send_Term(); } else { if (strlen(backup_buf)>=240) { pck.Add("Error: Message too large."); Send_Response(pck); Send_Term(); } else { CompiledPacket pck2; pck2.AddByte(LS_ADMIN_CONSOLE_COMMAND); pck2.AddByte(2+(unsigned char)strlen(backup_buf)); pck2.AddShort(0);//We don't want replies from the game servers pck2.Add(backup_buf); NetMessage s; s.pData=pck2.GetString(&s.dataSize); hash_map::iterator itr; for (itr=gGameServers.begin(); itr!=gGameServers.end(); itr++) { s.networkId=itr->second.networkId; gpInternalComm->SendData(&s); } pck2.Clear(); if (gGameServers.size()==0) { pck.Add("No game servers connected."); Send_Response(pck); Send_Term(); } else { pck.Add("Broadcast sent to game servers."); Send_Response(pck); Send_Term(); } } } } else if (IsCommand("version")) { pck.Add("GWLP Login Server v"); pck.Add(VERSION); pck.Add(" Admin Interface."); Send_Response(pck); Send_Term(); } else if (IsCommand("mkadmin")) { if (num_args<2) { pck.Add("Syntax: mkadmin {AccountID}\n"); } else { char query[160]; sprintf(query, "UPDATE accounts SET AccessLevel=%u WHERE AccountID=%u LIMIT 1@NOSTATUS", 100, atoi(args[1])); gDatabase.Query(query, (long)strlen(query)); pck.Add("Changed access level on account."); } Send_Response(pck); Send_Term(); } else if (IsCommand("mkgm")) { if (num_args<3) { pck.Add("Syntax: mkgm {CharacterID} {GroupID}\n"); } else { char query[160]; sprintf(query, "UPDATE characters SET GroupID=%u WHERE ID=%u LIMIT 1@NOSTATUS", atoi(args[2]), atoi(args[1])); gDatabase.Query(query, (long)strlen(query)); pck.Add("Changed character to GM of group %u", atoi(args[2])); } Send_Response(pck); Send_Term(); } else if (IsCommand("kick")) { if (num_args==1) { pck.Add("Syntax: kick {NetworkID}"); } else { gpLoginServer->Kick(atoi(args[1])); gCoreLog.notice("Admin %s kicked %u from the network.", pAl->accName, atoi(args[1])); pck.Add("%u kicked from the network.", atoi(args[1])); } Send_Response(pck); Send_Term(); } else if (IsCommand("suspend")) { if (num_args<3) { pck.Add("Syntax: suspend {AccountID} {Duration in Hours}"); } else { time_t ctime=time(NULL); char query[160]; sprintf(query, "UPDATE accounts SET AccessLevel=25, TimeAccountMarked=%u, DurationOfMark=%u WHERE AccountID=%u LIMIT 1@NOSTATUS", ctime, atoi(args[2]), atoi(args[1])); gDatabase.Query(query, (long)strlen(query)); char temp[100]; sprintf(temp, "Admin %s suspended account %u.", pAl->accName, atoi(args[1])); ServerEvent(pAl->accountId, "SUSPEND", temp, &gDatabase); pck.Add("Account %u has been suspended.", atoi(args[1])); hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { if (itr->second.accountId==atoi(args[1])) { gpLoginServer->Kick(itr->second.networkId); break; } } } } Send_Response(pck); Send_Term(); } else if (IsCommand("ban")) { if (num_args==1) { pck.Add("Syntax: ban {AccountID}"); } else { time_t ctime=time(NULL); char query[130]; sprintf(query, "UPDATE accounts SET AccessLevel=0, TimeAccountMarked=%u WHERE AccountID=%u LIMIT 1@NOSTATUS", ctime, atoi(args[1])); gDatabase.Query(query, (long)strlen(query)); char temp[100]; sprintf(temp, "Admin %s banned account %u.", pAl->accName, atoi(args[1])); ServerEvent(pAl->accountId, "BAN", temp, &gDatabase); pck.Add("Account %u has been banned.", atoi(args[1])); hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { if (itr->second.accountId==atoi(args[1])) { gpLoginServer->Kick(itr->second.networkId); break; } } } } Send_Response(pck); Send_Term(); } else if (IsCommand("unban")) { if (num_args==1) { pck.Add("Syntax: unban {AccountID}"); } else { char query[100]; sprintf(query, "UPDATE accounts SET AccessLevel=50 WHERE AccountID=%u LIMIT 1@NOSTATUS", atoi(args[1])); gDatabase.Query(query, (long)strlen(query)); char temp[100]; sprintf(temp, "Admin %s unbanned account %u.", pAl->accName, atoi(args[1])); ServerEvent(pAl->accountId, "UNBAN", temp, &gDatabase); pck.Add("Account %u has been unbanned.", atoi(args[1])); } Send_Response(pck); Send_Term(); } else if (IsCommand("playerlist")) { if (gLoginInfo.size()!=0) { pck.Add("----------Authenticated Players-----------"); } Send_Response(pck); hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { LOCAL_DATA* pLir=&itr->second; pck.Add("NetID: %u AcctID: %u Status: ", pLir->networkId, pLir->accountId); if (pLir->gameServerId>0) { pck.Add("IN-GAME CharID: %u ZoneID: %u", pLir->characterId, pLir->zoneId); } else { pck.Add("OTHER "); } Send_Response(pck); } } if (gLoginInfo.size()!=0) { pck.Add("\n----------Network Connections-----------"); } Send_Response(pck); for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (!BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED) && !BIT_TEST(itr->second.bitfield, LD_UPDATE_CONNECTION)) { SOCKETINFO s=gpLoginServer->GetClientById(itr->second.networkId); pck.Add("NetID: %u IP: %u.%u.%u.%u", itr->second.networkId, s.ip[0], s.ip[1], s.ip[2], s.ip[3]); Send_Response(pck); } } if (gLoginInfo.size()==0) { pck.Add("No connections are present on the auth server."); Send_Response(pck); } Send_Term(); } else if (IsCommand("serverlock")) { if (num_args==1) { pck.Add("Syntax: serverlock {state=0 or 1}"); } else { bool server_lock=false; if (atoi(args[1])>=1) { server_lock=true; } gServerStatus.adminLock=server_lock; if (gServerStatus.adminLock) { pck.Add("Auth Server is now Locked. Only admins(AccessLevel>50) can log-in."); ServerEvent(pAl->accountId, "LOCKED", "Auth server is now locked.", &gDatabase); } else { pck.Add("Auth Server is now Unlocked. Anyone can log-in."); ServerEvent(pAl->accountId, "UNLOCKED", "Auth server is now unlocked.", &gDatabase); } } Send_Response(pck); Send_Term(); } else if (IsCommand("cputhrottle")) { if (num_args==1) { pck.Add("Syntax: cputhrottle {state=0 or 1}"); } else { bool throttle_cpu=false; if (atoi(args[1])>=1) { throttle_cpu=true; } gServerConfig.throttleCpu=throttle_cpu; if (gServerConfig.throttleCpu) { pck.Add("CPU Throttling on. Using very little CPU time."); ServerEvent(pAl->accountId, "CPU", "Auth server CPU throttled.", &gDatabase); } else { pck.Add("CPU Throttling off. Using as much CPU time as possible."); ServerEvent(pAl->accountId, "CPU", "Auth server CPU unthrottled.", &gDatabase); } } Send_Response(pck); Send_Term(); } else if (IsCommand("restart")) { if (num_args==1) { srand((unsigned int)TimerGetTime()); admin_auth_code=1+rand()%32000; pck.Add("Syntax: restart {auth code}\n"); pck.Add("Auth Code: %u", admin_auth_code); Send_Response(pck); Send_Term(); } else { int auth_code=atoi(args[1]); if (auth_code==admin_auth_code) { char temp[100]; sprintf(temp, "Auth Server restart Authorized by %s. Restarting the server...", pAl->accName); ServerEvent(pAl->accountId, "RESTART", temp, &gDatabase); pck.Add("Restart Authorized. Restarting the server..."); Restart(); } else { pck.Add("Restart authorization failed."); Send_Response(pck); Send_Term(); } } } else if (IsCommand("shutdown")) { if (num_args==1) { srand((unsigned int)TimerGetTime()); admin_auth_code=1+rand()%32000; pck.Add("Syntax: shutdown {auth code}\n"); pck.Add("Auth Code: %u", admin_auth_code); Send_Response(pck); Send_Term(); } else { int auth_code=atoi(args[1]); if (auth_code==admin_auth_code) { char temp[100]; sprintf(temp, "Auth Server shutdown Authorized by %s. Shutting down...", pAl->accName); ServerEvent(pAl->accountId, "SHUTDOWN", temp, &gDatabase); pck.Add("Shutdown Authorized. Shutting down..."); Shutdown(); exit(1); } else { pck.Add("Shutdown authorization failed."); Send_Response(pck); Send_Term(); } } } else if (IsCommand("stats")) { //Output the lock status pck.Add("Lock Status: "); if (gServerStatus.adminLock) { pck.Add("LOCKED"); } else { pck.Add("UNLOCKED"); } Send_Response(pck); //Output the cpu throttle state pck.Add("CPU Usage: "); if (gServerConfig.throttleCpu) { pck.Add("THROTTLED"); } else { pck.Add("FULL"); } Send_Response(pck); //Count the number of authenticated players unsigned long num_players=0; hash_map::iterator itr; for (itr=gLoginInfo.begin(); itr!=gLoginInfo.end(); itr++) { if (BIT_TEST(itr->second.bitfield, LD_AUTHENTICATED)) { num_players++; } } //Number of players char temp[300]; sprintf(temp, "Players Current: %u/%u Peak: %u", num_players, gServerConfig.maxPlayers, gServerStatus.peakPlayers); pck.Add(temp); Send_Response(pck); //Number of game servers sprintf(temp, "Game Servers: %u/%u connected.", gGameServers.size(), gServerConfig.maxGameServers); pck.Add(temp); Send_Response(pck); //Output the crash status if (gServerConfig.serverHasCrashed) { pck.Add("Crash Status: Server has crashed. Please deal with the logs in /CrashInfo"); } else { pck.Add("Crash Status: No Crash Detected"); } Send_Response(pck); //Output the uptime time_t ctime=time(NULL); unsigned long tseconds=(unsigned long)difftime(ctime, gServerStatus.startTime); int days=tseconds/86400; int rSec=tseconds%86400; int hours=rSec/3600; rSec=rSec%3600; int minutes=rSec/60; rSec=rSec%60; int seconds=rSec; pck.Add("Uptime: %u day(s) %u hour(s) %u minute(s) %u second(s).", days, hours, minutes, seconds); Send_Response(pck); Send_Term(); } else if (IsCommand("netstats")) { //Network statistics Server *servers[2]; servers[0]=gpLoginServer; servers[1]=gpInternalComm; for (int i=0; i<2; i++) { NET_REPORT *n=servers[i]->GetReport(); pck.Add("-----------------------------------------\n"); pck.Add("Stats for %s %u Errors %u Warnings\n", servers[i]->GetName(), n->numErrors, n->numWarnings); pck.Add("-----------------------------------------"); Send_Response(pck); pck.Add("In: %u b/s Peak: %u b/s\n", n->packetsPerSecIn, n->peakBytesPerSecIn); pck.Add("Out: %u b/s Peak: %u b/s", n->packetsPerSecOut, n->peakBytesPerSecOut); Send_Response(pck); pck.Add("Avg In: %u b/s Peak: %u b/s\n", n->avgBytesPerSecIn, n->peakAvgBytesPerSecIn); pck.Add("Avg Out: %u b/s Peak: %u b/s", n->avgBytesPerSecOut, n->peakAvgBytesPerSecOut); Send_Response(pck); pck.Add("In: %f kb/s Peak: %f kb/s\n", n->avgBytesPerSecIn/1024.0, n->peakBytesPerSecIn/1024.0); pck.Add("Out: %f kb/s Peak: %f kb/s\n", n->avgBytesPerSecOut/1024.0, n->peakBytesPerSecOut/1024.0); Send_Response(pck); } Send_Term(); } else { log_admin_action=false; pck.Add("\"%s\" - Command not Found", backup_buf); Send_Response(pck); Send_Term(); } if (log_admin_action) { gCoreLog.notice("Admin %s used %s", pAl->accName, args[0]); } }; //************************************ // Name: AuthorizeAdminCon // // Processes the admin console account query. Verifies that the account is allowed to use the admin console and that the password is correct. // // Parameters: // pResult - Database query result // pAl - Admin's data // // Return: // //************************************ int AuthorizeAdminCon(QUERY_RESULT* pResult, AdminList* pAl) { //The database failed. =/ if (pResult->pResult==NULL) { CompiledPacket pck; pck.AddShort(0x0E); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); return -1; } //Make sure we got a row from the database if (mysql_num_rows(pResult->pResult)==0) { CompiledPacket pck; pck.AddShort(0x0F); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); return -1; } MYSQL_ROW row=mysql_fetch_row(pResult->pResult); unsigned long account_id=atoi(row[2]); pAl->accountId=account_id; //Make sure the network ID is the same so we don't ban good people by accident hash_map::iterator itr=gBruteForceTracker.find(account_id); if (itr!=gBruteForceTracker.end()) { if (itr->second.networkId!=pAl->networkId) { itr->second.networkId=pAl->networkId; itr->second.tries=0; itr->second.admin=true; memcpy(itr->second.ip, gpInternalComm->GetClientById(pAl->networkId).ip, 4); } } //Check for a password existing if (row[0]==NULL) { CompiledPacket pck; pck.AddShort(0x0E); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); gBruteForceTracker[account_id].tries++; gBruteForceTracker[account_id].networkId=pAl->networkId; gBruteForceTracker[account_id].admin=true; memcpy(gBruteForceTracker[account_id].ip, gpInternalComm->GetClientById(pAl->networkId).ip, 4); return -1; } //Compare the hashes unsigned char s_hash[32]; Util::ToBytes(row[0], (char*)s_hash, 32); if (memcmp(s_hash, pAl->passHash, 32)!=0) { CompiledPacket pck; pck.AddShort(0x0E); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); gBruteForceTracker[account_id].tries++; gBruteForceTracker[account_id].networkId=pAl->networkId; gBruteForceTracker[account_id].admin=true; memcpy(gBruteForceTracker[account_id].ip, gpInternalComm->GetClientById(pAl->networkId).ip, 4); return -1; } //Make sure this account has permission to use the admin console if (atoi(row[1])<51) { CompiledPacket pck; pck.AddShort(0x0C); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); return -1; } pAl->accessLevel=atoi(row[1]); //Send the success packet and change the local data flag CompiledPacket pck; pck.AddShort(0x0D); Util::SendCompiledPacket(&pck, pAl->networkId, gpInternalComm); pAl->authenticated=true; gCoreLog.notice("Admin %s logged in via admin console.", pAl->accName); return 0; }