// *************************************************************** // Function: HardCodedCommands.cpp // *************************************************************** #include "Main.h" #include "ConsoleScripts.h" #include "../../src/IC.h" unsigned long gAdminAuthCode=0; void Restart(); int Shutdown(); //************************************ // Name: PasswordResult // // Check if the password change succeeded or failed. // // Parameters: // pResult - Database query result // pLir - Player's data // // Return: // - zero //************************************ int PasswordResult(QUERY_RESULT* pResult, PLAYER_DATA* pLir) { if (pResult==NULL) { ConsoleWrite("Password change failed.", false, pLir->networkId, COMMAND_COLOR); return 0; } if (pResult->affectedRows==0) { ConsoleWrite("Current password incorrect.", false, pLir->networkId, COMMAND_COLOR); } else { ConsoleWrite("Password changed. Please remember to login with your new password.", false, pLir->networkId, COMMAND_COLOR); } return 0; } //************************************ // Name: console_password // // Hard coded change password command. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_password(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs<4) { ConsoleWrite("Syntax: password {currentPass} {newPass} {retypeNewPass}", adminConsole, networkId, COMMAND_COLOR); ConsoleWrite("Passwords can be 11 characters max, no spaces.", adminConsole, networkId, COMMAND_COLOR); return; } //Make sure the passwords are at least 7 characters if (strlen(args[1])<7 || strlen(args[2])<7 || strlen(args[3])<7) { ConsoleWrite("Passwords must be at least 7 characters long.", adminConsole, networkId, COMMAND_COLOR); return; } //Make sure the passwords are no longer than 11 characters if (strlen(args[1])>11 || strlen(args[2])>11 || strlen(args[3])>11) { ConsoleWrite("Passwords must be at most 11 characters long.", adminConsole, networkId, COMMAND_COLOR); return; } //Make sure the desired new password fields match if (strcmp(args[2], args[3])!=0) { ConsoleWrite("New password fields do not match.", adminConsole, networkId, COMMAND_COLOR); return; } //Get the local data and hash the passwords and convert to hex PLAYER_DATA* pLir=AccessLocalData(networkId); if (pLir!=NULL) { //Hash the current password and convert to hex unsigned char currentPassHash[32]; char currentPassHex[70]; Util::Hash((unsigned char*)args[1], currentPassHash, strlen(args[1])); Util::BinToHex(currentPassHash, 32, currentPassHex); //Hash the new password and convert to hex unsigned char newPassHash[32]; char newPassHex[70]; Util::Hash((unsigned char*)args[2], newPassHash, strlen(args[2])); Util::BinToHex(newPassHash, 32, newPassHex); //Build the SQL query char query[400]; sprintf(query, "UPDATE accounts SET Password=\"%s\" WHERE (Password=\"\" OR Password=\"%s\") AND AccountID=%u LIMIT 1@NOSTATUS", newPassHex+2, currentPassHex+2, pLir->accountId); pLir->queryId=gDatabase.Query(query, (long)strlen(query), true); pLir->QueryProcess=PasswordResult; } } //************************************ // Name: console_map // // Hard coded command to change maps. (This map will contain NO spawn data.) // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_map(char* args[], int numArgs, bool adminConsole, short networkId) { //Check for proper syntax if (numArgs==1) { ConsoleWrite("Syntax: map {zoneID}", adminConsole, networkId, COMMAND_COLOR); return; } int zone_id=atoi(args[1]); //Make sure we have info for this zone if (Instance::GetZoneInfo(zone_id)==-1) { char temp[100]; sprintf(temp, "No map data for %u.", zone_id); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); return; } //Request to go to this zone Instance::RequestMapChange(zone_id, networkId); } //************************************ // Name: console_rmap // // Changes map to a random map. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_rmap(char *args[], int numArgs, bool adminConsole, short networkId) { //Request to go to this zone Instance::RequestMapChange(Instance::GetRandomZone(), networkId); } //************************************ // Name: ServerEvent // // Logs a server event to the database. // // Parameters: // adminAccountId - Admin's account id // pEvent - Event // pInfo - Info about the event // pDatabase - Pointer to a GWLPDatabase // // 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)); } //************************************ // Name: KickPlayer // // Kicks a player from the server. // // Parameters: // networkId - Network id of player to kicked // accountId - Account id // // Return: // //************************************ void KickPlayer(short networkId, unsigned long accountId) { NetMessage s; s.networkId=gpInternalComm->GetClientModeId(); //Prepare the kick packet unsigned char kick_packet[4]; PreparePacket(GS_KICK_PLAYER, &networkId, 2, kick_packet); s.pData=kick_packet; s.dataSize=4; gpInternalComm->SendData(&s); } //************************************ // Name: console_gm // // Toggles the GM sign above a character. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_gm(char* args[], int numArgs, bool adminConsole, short networkId) { PLAYER_DATA* pLir=AccessLocalData(networkId); Player* pPlayer=(Player*)pLir->pPlayer; if (pPlayer->GetAgent()->GetVitalFlag(VITAL_STATUS_GM)) { pPlayer->GetAgent()->UpdateVitalStatus(VITAL_STATUS_GM, false); } else { pPlayer->GetAgent()->UpdateVitalStatus(VITAL_STATUS_GM, true); } } //************************************ // Name: console_shutdown // // Command to shut down the server. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_shutdown(char* args[], int numArgs, bool adminConsole, short networkId) { PLAYER_DATA* pLir=AccessLocalData(networkId); if (numArgs==1) { srand((unsigned int)TimerGetTime()); gAdminAuthCode=1+rand()%32000; ConsoleWrite("Syntax: shutdown {auth code}", adminConsole, networkId, COMMAND_COLOR); char temp[25]; sprintf(temp, "Auth Code: %u", gAdminAuthCode); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } else { int auth_code=atoi(args[1]); if (auth_code==gAdminAuthCode) { char temp[100]; sprintf(temp, "Auth Server shutdown Authorized by %u. Shutting down the server...", pLir->accountId); ServerEvent(pLir->accountId, "RESTART", temp, &gDatabase); Shutdown(); exit(1); } else { ConsoleWrite("Shutdown authorization failed.", adminConsole, networkId, COMMAND_COLOR); } } } //************************************ // Name: console_restart // // Command to restart the server. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_restart(char* args[], int numArgs, bool adminConsole, short networkId) { PLAYER_DATA* pLir=AccessLocalData(networkId); if (numArgs==1) { srand((unsigned int)TimerGetTime()); gAdminAuthCode=1+rand()%32000; ConsoleWrite("Syntax: restart {auth code}", adminConsole, networkId, COMMAND_COLOR); char temp[25]; sprintf(temp, "Auth Code: %u", gAdminAuthCode); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } else { int auth_code=atoi(args[1]); if (auth_code==gAdminAuthCode) { char temp[100]; sprintf(temp, "Auth Server restart Authorized by %u. Restarting the server...", pLir->accountId); ServerEvent(pLir->accountId, "RESTART", temp, &gDatabase); Restart(); } else { ConsoleWrite("Restart authorization failed.", adminConsole, networkId, COMMAND_COLOR); } } } //************************************ // Name: console_ban // // Command to ban a player's account. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_ban(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: ban {Player ID}", adminConsole, networkId, COMMAND_COLOR); return; } //Get the command user's info PLAYER_DATA* pAdmin_lir=AccessLocalData(networkId); if (pAdmin_lir==NULL){return;} Player* pAdminPlayer=(Player*)pAdmin_lir->pPlayer; //Get the targets info PLAYER_DATA* pTarget_lir=AccessLocalData(atoi(args[1])); if (pTarget_lir==NULL){return;} Player* pTargetPlayer=(Player*)pTarget_lir->pPlayer; //Get the instance the target is in Instance* pInstance=AccessInstance(pTarget_lir->instanceId); if (pAdmin_lir==NULL || pAdminPlayer==NULL || pTarget_lir==NULL || pTargetPlayer==NULL || pInstance==NULL) { ConsoleWrite("Failed!", adminConsole, networkId, COMMAND_COLOR); return; } //Kick the player and provide notices KickPlayer(pTarget_lir->lsnetworkId, pTargetPlayer->GetAccountId()); char temp[100]; sprintf(temp, "Admin %s:%u has banned %s:%u.", pAdminPlayer->GetPlayerName(), pAdminPlayer->GetAccountId(), pTargetPlayer->GetPlayerName(), pTargetPlayer->GetAccountId()); time_t ctime=time(NULL); char query[130]; sprintf(query, "UPDATE accounts SET AccessLevel=0, TimeAccountMarked=%u WHERE AccountID=%u AND AccessLevel<=50 LIMIT 1@NOSTATUS", ctime, pTargetPlayer->GetAccountId()); gDatabase.Query(query, (long)strlen(query)); pInstance->Broadcast(temp, COMMAND_COLOR, 0); ServerEvent(pAdminPlayer->GetAccountId(), "BAN", temp, &gDatabase); } //************************************ // Name: console_suspend // // Command to suspend a player's account. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_suspend(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs<3) { ConsoleWrite("Syntax: suspend {Player ID} {Duration in Hours}", adminConsole, networkId, COMMAND_COLOR); return; } //Get the command user's info PLAYER_DATA* pAdmin_lir=AccessLocalData(networkId); if (pAdmin_lir==NULL){return;} Player* pAdmin_player=(Player*)pAdmin_lir->pPlayer; //Get the targets info PLAYER_DATA* pTarget_lir=AccessLocalData(atoi(args[1])); if (pTarget_lir==NULL){return;} Player* pTarget_player=(Player*)pTarget_lir->pPlayer; //Get the instance the target is in Instance* pInstance=AccessInstance(pTarget_lir->instanceId); if (pAdmin_lir==NULL || pAdmin_player==NULL || pTarget_lir==NULL || pTarget_player==NULL || pInstance==NULL) { ConsoleWrite("Failed!", adminConsole, networkId, COMMAND_COLOR); return; } KickPlayer(pTarget_lir->lsnetworkId, pTarget_player->GetAccountId()); char temp[100]; sprintf(temp, "Admin %s:%u has suspended %s:%u.", pAdmin_player->GetPlayerName(), pAdmin_player->GetAccountId(), pTarget_player->GetPlayerName(), pTarget_player->GetAccountId()); time_t ctime=time(NULL); int duration=atoi(args[2]); char query[160]; sprintf(query, "UPDATE accounts SET AccessLevel=25, TimeAccountMarked=%u, DurationOfMark=%u WHERE AccountID=%u AND AccessLevel<=50 LIMIT 1@NOSTATUS", ctime, duration, pTarget_player->GetAccountId()); gDatabase.Query(query, (long)strlen(query)); pInstance->Broadcast(temp, COMMAND_COLOR, 0); ServerEvent(pAdmin_player->GetAccountId(), "SUSPEND", temp, &gDatabase); } //************************************ // Name: console_kick // // Command to kick a player from the server. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_kick(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: kick {Player ID}", adminConsole, networkId, COMMAND_COLOR); return; } //Get the command user's info PLAYER_DATA* pAdmin_lir=AccessLocalData(networkId); if (pAdmin_lir==NULL){return;} Player* pAdmin_player=(Player*)pAdmin_lir->pPlayer; //Get the targets info PLAYER_DATA* pTarget_lir=AccessLocalData(atoi(args[1])); if (pTarget_lir==NULL){return;} Player* pTarget_player=(Player*)pTarget_lir->pPlayer; //Get the instance the target is in Instance* pInstance=AccessInstance(pTarget_lir->instanceId); if (pAdmin_lir==NULL || pAdmin_player==NULL || pTarget_lir==NULL || pTarget_player==NULL || pInstance==NULL) { ConsoleWrite("Failed!", adminConsole, networkId, COMMAND_COLOR); return; } KickPlayer(pTarget_lir->lsnetworkId, pTarget_player->GetAccountId()); gCoreLog.notice("Admin %s:%u has kicked %s:%u from the server.", pAdmin_player->GetPlayerName(), pAdmin_player->GetAccountId(), pTarget_player->GetPlayerName(), pTarget_player->GetAccountId()); char temp[100]; sprintf(temp, "%s has been kicked from the server.", pTarget_player->GetPlayerName()); pInstance->Broadcast(temp, COMMAND_COLOR, 0); } //************************************ // Name: console_playerlist // // Lists on all the players in the instance or server depending on the context. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_playerlist(char* args[], int numArgs, bool adminConsole, short networkId) { if (adminConsole) { ConsoleWrite("-------Global Players List------", adminConsole, networkId, COMMAND_COLOR); hash_map::iterator itr; for (itr=GameServInfo.begin(); itr!=GameServInfo.end(); itr++) { PLAYER_DATA* pLir=&itr->second; if (pLir->authorized) { if (pLir->pPlayer!=NULL) { Player* pPlayer=(Player*)pLir->pPlayer; int group_id=pPlayer->GetGroupId(); char temp[150]; sprintf(temp, "%s ID: %u Zone: %u InstID: %u AgID: %u GroupID: %u", pPlayer->GetPlayerName(), pPlayer->GetnetworkId(), AccessInstance(pLir->instanceId)->GetZoneId(), pLir->instanceId, pPlayer->GetAgentId(), group_id); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } } } } else { ConsoleWrite("-------Instance Players List------", adminConsole, networkId, COMMAND_COLOR); PLAYER_DATA* pLocal_data=AccessLocalData(networkId); hash_map::iterator itr; for (itr=GameServInfo.begin(); itr!=GameServInfo.end(); itr++) { PLAYER_DATA* pLir=&itr->second; if (pLir->authorized && pLir->instanceId==pLocal_data->instanceId) { if (pLir->pPlayer!=NULL) { Player* pPlayer=(Player*)pLir->pPlayer; int group_id=pPlayer->GetGroupId(); char temp[150]; sprintf(temp, "%s ID: %u Zone: %u InstID: %u AgID: %u GroupID: %u", pPlayer->GetPlayerName(), pPlayer->GetnetworkId(), AccessInstance(pLir->instanceId)->GetZoneId(), pLir->instanceId, pPlayer->GetAgentId(), group_id); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } } } } } //************************************ // Name: console_instancelist // // List all instances and some info about them. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_instancelist(char* args[], int numArgs, bool adminConsole, short networkId) { ConsoleWrite("-------Active Instances-------", adminConsole, networkId, COMMAND_COLOR); hash_map::iterator itr; for (itr=gInstances.begin(); itr!=gInstances.end(); itr++) { Instance* pInstance=&itr->second; char temp[200]; sprintf(temp, "ID: %u Zone: %u Players: %u/%u", pInstance->GetInstanceId(), pInstance->GetZoneId(), pInstance->GetNumPlayers(), pInstance->GetCapacity()); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } } //************************************ // Name: console_bug // // Command to file a bug report in the database. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_bug(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: /bug {comments}", adminConsole, networkId, COMMAND_COLOR); return; } //Change any breaking characters in the bug string while(strstr(args[10], "\"")!=NULL) { char* t=strstr(args[10], "\""); *t=(char)39; } char query[1000]; sprintf(query, "INSERT INTO bug_reports (Comments, ReporterAccountID, Status) VALUES (\"%s\", %u, 'open')", args[10], AccessLocalData(networkId)->accountId); gDatabase.Query(query, strlen(query)); ConsoleWrite("Thank you. Your bug report has been submitted.", adminConsole, networkId, COMMAND_COLOR); } //************************************ // Name: console_version // // Command to display the computer version. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_version(char* args[], int numArgs, bool adminConsole, short networkId) { char temp[150]; sprintf(temp, "GWLP Game Server v%s", VERSION); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } //************************************ // Name: console_netstats // // Command to show the network server statistics. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_netstats(char* args[], int numArgs, bool adminConsole, short networkId) { //Network statistics Server* pServers[2]; pServers[0]=gpGameServer; pServers[1]=gpInternalComm; for (int i=0; i<2; i++) { NET_REPORT* pNet_report=pServers[i]->GetReport(); char temp[250]; sprintf(temp, "----------Stats for %s %u Errors %u Warnings", pServers[i]->GetName(), pNet_report->numErrors, pNet_report->numWarnings); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "In: %u b/s Peak: %u b/s", pNet_report->packetsPerSecIn, pNet_report->peakBytesPerSecIn); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "Out: %u b/s Peak: %u b/s", pNet_report->packetsPerSecOut, pNet_report->peakBytesPerSecOut); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "Avg In: %u b/s Peak: %u b/s", pNet_report->avgBytesPerSecIn, pNet_report->peakAvgBytesPerSecIn); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "Avg Out: %u b/s Peak: %u b/s", pNet_report->avgBytesPerSecOut, pNet_report->peakAvgBytesPerSecOut); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "In: %f kb/s Peak: %f kb/s", pNet_report->avgBytesPerSecIn/1024.0, pNet_report->peakBytesPerSecIn/1024.0); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); sprintf(temp, "Out: %f kb/s Peak: %f kb/s", pNet_report->avgBytesPerSecOut/1024.0, pNet_report->peakBytesPerSecOut/1024.0); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } } //************************************ // Name: console_stats // // Command to show server statistics and status. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_stats(char* args[], int numArgs, bool adminConsole, short networkId) { ConsoleWrite("---------------Game Server Stats", adminConsole, networkId, COMMAND_COLOR); char temp[150]; //Output the cpu usage if (gServerConfig.throttleCpu) { ConsoleWrite("CPU Usage: THROTTLED", adminConsole, networkId, COMMAND_COLOR); } else { ConsoleWrite("CPU Usage: FULL", adminConsole, networkId, COMMAND_COLOR); } //Output the number of players sprintf(temp, "Current #Players: %u", GameServInfo.size()); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); //Current number of instances sprintf(temp, "Current #Instances: %u", gInstances.size()); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); //Crash status if (gServerConfig.serverHasCrashed) { ConsoleWrite("Crash Status: CRASHED! Please see /CrashInfo for dump files.", adminConsole, networkId, COMMAND_COLOR); } else { ConsoleWrite("Crash Status: No crash detected", adminConsole, networkId, COMMAND_COLOR); } //Uptime time_t ctime=time(NULL); unsigned long tseconds=difftime(ctime, gServerStats.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; sprintf(temp, "Uptime: %u day(s) %u hour(s) %u minute(s) %u second(s).", days, hours, minutes, seconds); ConsoleWrite(temp, adminConsole, networkId, COMMAND_COLOR); } //************************************ // Name: console_throttlecpu // // Toggle CPU throttle on and off // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_throttlecpu(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: /throttlecpu {state=0 or 1}", adminConsole, networkId, COMMAND_COLOR); return; } gServerConfig.throttleCpu=atoi(args[1]); if (gServerConfig.throttleCpu) { ConsoleWrite("Using as little CPU as possible.", adminConsole, networkId, COMMAND_COLOR); } else { ConsoleWrite("Using as much CPU as possible.", adminConsole, networkId, COMMAND_COLOR); } } //************************************ // Name: console_broadcast // // Command to broadcast a message to everyone on the server. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_broadcast(char *args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: /broadcast {message}", adminConsole, networkId, COMMAND_COLOR); return; } hash_map::iterator itr; for (itr=gInstances.begin(); itr!=gInstances.end(); itr++) { itr->second.Broadcast(args[10], BROADCAST_COLOR, 0); } if (adminConsole) { ConsoleWrite("Message Broadcasted", adminConsole, networkId, COMMAND_COLOR); } } struct HELPME_COMMAND { char name[50]; }; //************************************ // Name: console_helpme // // Command to display all available commands for the calling user. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_helpme(char* args[], int numArgs, bool adminConsole, short networkId) { int numCommandsPerLine=5;//X + 1 //Get the group ID for restricted command checking int group_id=100; if (!adminConsole) { PLAYER_DATA* pLir=AccessLocalData(networkId); Player* pPlayer=(Player*)pLir->pPlayer; group_id=pPlayer->GetGroupId(); } list allowedCommands; //Build the restricted commands allowed list list::iterator itr; for (itr=gConsoleCommands.begin(); itr!=gConsoleCommands.end(); itr++) { if ((*itr)->restricted && gpPermissionGroups->HasPermission(group_id, (*itr)->pFunctionName+8)) { if (((*itr)->allowedModes==0 && !adminConsole) || ((*itr)->allowedModes==1 && adminConsole) || ((*itr)->allowedModes>=2)) { HELPME_COMMAND h; strcpy(h.name, (*itr)->pFunctionName+8); allowedCommands.push_back(h); } } } if (allowedCommands.size()>0) { //Output the restricted commands ConsoleWrite("Restricted Commands:", adminConsole, networkId, 8); int count=0; char buf[150]; memset(buf, 0, 150); int remaining=allowedCommands.size(); list::iterator itr2; for (itr2=allowedCommands.begin(); itr2!=allowedCommands.end(); itr2++) { char temp[60]; sprintf(temp, "%s, ", itr2->name); strcat(buf, temp); if (count>=numCommandsPerLine || count>=remaining-1) { ConsoleWrite(buf, adminConsole, networkId, COMMAND_COLOR); memset(buf, 0, 150); remaining-=count; count=0; } count++; } } allowedCommands.clear(); //Build the normal commands list for (itr=gConsoleCommands.begin(); itr!=gConsoleCommands.end(); itr++) { if (!(*itr)->restricted) { if (((*itr)->allowedModes==0 && !adminConsole) || ((*itr)->allowedModes==1 && adminConsole) || ((*itr)->allowedModes>=2)) { HELPME_COMMAND h; strcpy(h.name, (*itr)->pFunctionName+8); allowedCommands.push_back(h); } } } //Output the unrestricted commands if (allowedCommands.size()>0) { ConsoleWrite("Commands/Emotes:", adminConsole, networkId, 8); int count=0; char buf[150]; memset(buf, 0, 150); int remaining=allowedCommands.size(); list::iterator itr2; for (itr2=allowedCommands.begin(); itr2!=allowedCommands.end(); itr2++) { char temp[60]; sprintf(temp, "%s, ", itr2->name); strcat(buf, temp); if (count>=numCommandsPerLine || count>=remaining-1) { ConsoleWrite(buf, adminConsole, networkId, COMMAND_COLOR); remaining-=count; count=0; memset(buf, 0, 150); } count++; } } } //************************************ // Name: console_replay // // Command to replay a chunk of data loaded from the /replay folder. // // Parameters: // - Standard hard coded command stuff // // Return: // //************************************ void console_replay(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: /replay {filename}", adminConsole, networkId, COMMAND_COLOR); return; } char file[200]; sprintf(file, "Data/Packets/Replay/%s", args[1]); std::ifstream fin(file, std::ios::binary); if (!fin.fail()) { int begin=fin.tellg(); fin.seekg(0, ios::end); int end=fin.tellg(); int size=end-begin; fin.seekg(0, ios::beg); char* pBuffer=new char[size]; fin.read(pBuffer, size); fin.close(); NetMessage s; s.networkId=networkId; s.pData=(unsigned char*)pBuffer; s.dataSize=size; gpGameServer->SendData(&s); delete [] pBuffer; ConsoleWrite("Replay Sent!", adminConsole, networkId, COMMAND_COLOR); } else { ConsoleWrite("File not found!", adminConsole, networkId, COMMAND_COLOR); return; } fin.close(); }