/mani_admin_plugin/mani_client.cpp
C++ | 8173 lines | 8079 code | 51 blank | 43 comment | 63 complexity | d5fca107aa2295d573d9572edff9b86f MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- //
- // Mani Admin Plugin
- //
- // Copyright 2009-2014 Giles Millward (Mani). All rights reserved.
- //
- // This file is part of ManiAdminPlugin.
- //
- // Mani Admin Plugin is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // Mani Admin Plugin is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with Mani Admin Plugin. If not, see <http://www.gnu.org/licenses/>.
- //
-
-
- //
-
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <time.h>
- #include "interface.h"
- #include "filesystem.h"
- #include "engine/iserverplugin.h"
- #include "iplayerinfo.h"
- #include "eiface.h"
- #include "inetchannelinfo.h"
- #include "mani_client_flags.h"
- #include "mani_memory.h"
- #include "mani_convar.h"
- #include "mani_player.h"
- #include "mani_output.h"
- #include "mani_parser.h"
- #include "mani_main.h"
- #include "mani_mysql.h"
- #include "mani_database.h"
- #include "mani_language.h"
- #include "mani_keyvalues.h"
- #include "mani_commands.h"
- #include "mani_util.h"
- #include "mani_help.h"
- #include "mani_client_util.h"
- #include "mani_client.h"
- #include "mani_client_sql.h"
- #include "mani_reservedslot.h"
-
- #include <map>
-
- #ifdef SOURCEMM
- #include "mani_client_interface.h"
- #endif
-
- extern IFileSystem *filesystem;
- extern IVEngineServer *engine; // helper functions (messaging clients, loading content, making entities, running commands, etc)
- extern IPlayerInfoManager *playerinfomanager;
- extern int con_command_index;
- extern bool war_mode;
- extern int max_players;
-
- #ifdef SOURCEMM
- extern unsigned int g_CallBackCount;
- extern SourceHook::CVector<AdminInterfaceListnerStruct *>g_CallBackList;
- #endif
-
- ConVar mani_disable_old_clients("mani_disable_old_clients","1",0, "Disallows the engine to read the old client files (adminlist.txt, admingroups.txt, immunitylist.txt)");
-
- static int sort_mask_list ( const void *m1, const void *m2);
-
- static int sort_mask_list ( const void *m1, const void *m2)
- {
- struct mask_level_t *mi1 = (struct mask_level_t *) m1;
- struct mask_level_t *mi2 = (struct mask_level_t *) m2;
-
- int result = strcmp(mi1->class_type, mi2->class_type);
- if (result != 0) return result;
- return mi1->level_id - mi2->level_id;
- }
-
-
- inline bool FStruEq(const char *sz1, const char *sz2)
- {
- return(Q_strcmp(sz1, sz2) == 0);
- }
-
- inline bool FStrEq(const char *sz1, const char *sz2)
- {
- return(Q_stricmp(sz1, sz2) == 0);
- }
-
-
- ManiClient::ManiClient()
- {
- // Init
- for (int i = 0; i < MANI_MAX_PLAYERS; i++)
- {
- active_client_list[i] = NULL;
- }
-
- this->InitAdminFlags();
- this->InitImmunityFlags();
- gpManiClient = this;
- }
-
- ManiClient::~ManiClient()
- {
- // Cleanup
- FreeClients();
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Player active on server
- //---------------------------------------------------------------------------------
- void ManiClient::NetworkIDValidated(player_t *player_ptr)
- {
- int index;
-
- index = this->FindClientIndex(player_ptr);
- if (index == -1)
- {
- active_client_list[player_ptr->index - 1] = NULL;
- }
- else
- {
- active_client_list[player_ptr->index - 1] = c_list[index];
-
- // Check levels to see if masking needs to be applied to other players
- if (!c_list[index]->level_list.IsEmpty())
- {
- this->SetupMasked();
- }
-
- #ifdef SOURCEMM
- for(unsigned int i=0;i<g_CallBackCount;i++)
- {
- AdminInterfaceListner *ptr = (AdminInterfaceListner *)g_CallBackList[i]->ptr;
- if(!ptr)
- continue;
-
- ptr->Client_Authorized(player_ptr->index);
- }
- #endif
- }
-
- return;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Check if client is officially labelled as admin
- //---------------------------------------------------------------------------------
- void ManiClient::ClientDisconnect(player_t *player_ptr)
- {
-
- if (active_client_list[player_ptr->index - 1] != NULL)
- {
- // Check if they had any level ids
- if (!active_client_list[player_ptr->index - 1]->level_list.IsEmpty())
- {
- // Reset pointer then call SetupMasks to reset other
- // active player masks
- active_client_list[player_ptr->index - 1] = NULL;
- this->SetupMasked();
- }
- else
- {
- active_client_list[player_ptr->index - 1] = NULL;
- }
- }
- UpdatePlayer( player_ptr );
- return;
- }
-
- void ManiClient::LevelShutdown() {
- WriteIPList();
- }
- //---------------------------------------------------------------------------------
- // Purpose: Parses the Admin config line setting flags
- //---------------------------------------------------------------------------------
-
- bool ManiClient::OldAddClient
- (
- char *file_details,
- old_style_client_t *client_ptr,
- bool is_admin
- )
- {
- char steam_id[MAX_NETWORKID_LENGTH]="";
- char ip_address[128]="";
- char name[MAX_PLAYER_NAME_LENGTH]="";
- char password[128]="";
- int i,j;
-
- Q_memset(client_ptr, 0, sizeof(old_style_client_t));
-
- // Setup flags for individual access
- if (is_admin)
- {
- for (int i = 0; i < MAX_ADMIN_FLAGS; i ++)
- {
- Q_strcpy(client_ptr->flags[i].flag_name, admin_flag_list[i].flag);
- if (mani_reverse_admin_flags.GetInt() == 1)
- {
- client_ptr->flags[i].enabled = false;
- }
- else
- {
- client_ptr->flags[i].enabled = true;
- }
- }
-
- client_ptr->flags[ALLOW_CLIENT_ADMIN].enabled = true;
- }
- else
- {
- for (int i = 0; i < MAX_IMMUNITY_FLAGS; i ++)
- {
- Q_strcpy(client_ptr->flags[i].flag_name, immunity_flag_list[i].flag);
-
- if (mani_reverse_immunity_flags.GetInt() == 1)
- {
- client_ptr->flags[i].enabled = true;
- }
- else
- {
- client_ptr->flags[i].enabled = false;
- }
- }
-
- client_ptr->flags[IMMUNITY_ALLOW_BASIC_IMMUNITY].enabled = true;
- }
-
- i = 0;
-
- if (file_details[i] != ';')
- {
- j = 0;
- for (;;)
- {
- if (file_details[i] == '\0')
- {
- // No more data
- steam_id[j] = '\0';
- Q_strcpy(client_ptr->steam_id, steam_id);
- return true;
- }
-
- // If reached space or tab break out of loop
- if (file_details[i] == ' ' ||
- file_details[i] == '\t' ||
- file_details[i] == ';')
- {
- steam_id[j] = '\0';
- break;
- }
-
- steam_id[j] = file_details[i];
- i++;
- j++;
- }
-
- Q_strcpy(client_ptr->steam_id, steam_id);
- }
-
- MMsg("%s ", steam_id);
-
- if (file_details[i] == ';')
- {
- i++;
- j = 0;
-
- for (;;)
- {
- if (file_details[i] == '\0')
- {
- // No more data
- ip_address[j] = '\0';
- Q_strcpy(client_ptr->ip_address, ip_address);
- return true;
- }
-
- // If reached space or tab break out of loop
- if (file_details[i] == ' ' ||
- file_details[i] == ';' ||
- file_details[i] == '\t')
- {
- ip_address[j] = '\0';
- break;
- }
-
- ip_address[j] = file_details[i];
- i++;
- j++;
- }
-
- Q_strcpy(client_ptr->ip_address, ip_address);
- }
-
- MMsg("%s ", ip_address);
-
- if (file_details[i] == ';' && file_details[i + 1] == '\"')
- {
- i += 2;
- j = 0;
-
- for (;;)
- {
- if (file_details[i] == '\0')
- {
- // No more data
- name[j] = '\0';
- Q_strcpy(client_ptr->name, name);
- return true;
- }
-
- // If reached space or tab break out of loop
- if (file_details[i] == '"')
- {
- i++;
- name[j] = '\0';
- break;
- }
-
- name[j] = file_details[i];
- i++;
- j++;
- }
-
- Q_strcpy(client_ptr->name, name);
- }
-
- MMsg("%s ", name);
-
- if (file_details[i] == ';')
- {
- i++;
- j = 0;
-
- for (;;)
- {
- if (file_details[i] == '\0')
- {
- // No more data
- password[j] = '\0';
- if (!client_ptr->steam_id && !client_ptr->ip_address && !client_ptr->name)
- {
- return false;
- }
-
- Q_strcpy(client_ptr->password, password);
- return true;
- }
-
- // If reached space or tab break out of loop
- if (file_details[i] == ' ' ||
- file_details[i] == '\t')
- {
- password[j] = '\0';
- break;
- }
-
- password[j] = file_details[i];
- i++;
- j++;
- }
-
- if (!client_ptr->steam_id && !client_ptr->ip_address && !client_ptr->name)
- {
- return false;
- }
-
- Q_strcpy(client_ptr->password, password);
- }
-
- MMsg("%s ", password);
-
- i++;
-
- while (file_details[i] == ' ' || file_details[i] == '\t')
- {
- i++;
- }
-
- const char *flags_string = &(file_details[i]);
-
- if (is_admin)
- {
- if (group_list.Find(ADMIN, flags_string))
- {
- strcpy(client_ptr->group_id, flags_string);
- for (int k = 0; k < MAX_ADMIN_FLAGS; k ++)
- {
- client_ptr->flags[k].enabled = false;
- }
-
- return true;
- }
- }
- else
- {
- if (group_list.Find(IMMUNITY, flags_string))
- {
- strcpy(client_ptr->group_id, flags_string);
- for (int k = 0; k < MAX_IMMUNITY_FLAGS; k ++)
- {
- client_ptr->flags[k].enabled = false;
- }
-
- return true;
- }
- }
-
- while (file_details[i] != '\0')
- {
- if (is_admin)
- {
- for (int k = 0; k < MAX_ADMIN_FLAGS; k ++)
- {
- if (file_details[i] == admin_flag_list[k].flag[0])
- {
- if (mani_reverse_admin_flags.GetInt() == 1)
- {
- client_ptr->flags[k].enabled = true;
- }
- else
- {
- client_ptr->flags[k].enabled = false;
- }
-
- break;
- }
- }
- }
- else
- {
- for (int k = 0; k < MAX_IMMUNITY_FLAGS; k ++)
- {
- if (file_details[i] == immunity_flag_list[k].flag[0])
- {
- if (mani_reverse_immunity_flags.GetInt() == 1)
- {
- client_ptr->flags[k].enabled = false;
- }
- else
- {
- client_ptr->flags[k].enabled = true;
- }
-
- break;
- }
- }
- }
-
- i++;
- }
-
-
- MMsg("\n");
- return true;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Parses the Admin Group config line setting flags
- //---------------------------------------------------------------------------------
- void ManiClient::OldAddGroup(char *file_details, char *class_type)
- {
- char group_id[128]="";
- int i,j;
- bool reverse_flags = mani_reverse_admin_flags.GetBool();
-
- if (file_details[0] != '\"') return;
-
- i = 1;
- j = 0;
-
- for (;;)
- {
- if (file_details[i] == '\0')
- {
- // No more data
- group_id[j] = '\0';
-
- if (reverse_flags)
- {
- // No point adding group
- return;
- }
-
- GlobalGroupFlag *g_flag = group_list.AddGroup(class_type, group_id);
- const DualStrKey *key_value = NULL;
- for (const char *desc = flag_desc_list.FindFirst(class_type, &key_value); desc != NULL; desc = flag_desc_list.FindNext(class_type, &key_value))
- {
- g_flag->SetFlag(key_value->key2, true);
- }
- return;
- }
-
-
- // If reached end quote
- if (file_details[i] == '\"')
- {
- group_id[j] = '\0';
- break;
- }
-
- group_id[j] = file_details[i];
- i++;
- j++;
- }
-
- // Populate all the flags if needed
- if (!reverse_flags)
- {
- group_list.AddGroup(class_type, group_id);
- GlobalGroupFlag *g_flag = group_list.AddGroup(class_type, group_id);
- const DualStrKey *key_value = NULL;
- for (const char *desc = flag_desc_list.FindFirst(class_type, &key_value); desc != NULL; desc = flag_desc_list.FindNext(class_type, &key_value))
- {
- g_flag->SetFlag(key_value->key2, true);
- }
- }
-
- i++;
-
- while (file_details[i] != '\0')
- {
- char temp_string[8];
-
- snprintf(temp_string, sizeof(temp_string), "%c", file_details[i]);
-
- if (flag_desc_list.IsValidFlag(class_type, temp_string))
- {
- if (!reverse_flags)
- {
- GlobalGroupFlag *g_flag = group_list.AddGroup(class_type, group_id);
- if (g_flag)
- {
- g_flag->SetFlag(temp_string, false);
- }
- }
- else
- {
- GlobalGroupFlag *g_flag = group_list.AddGroup(class_type, group_id);
- if (g_flag)
- {
- g_flag->SetFlag(temp_string, true);
- }
- }
- }
-
- i++;
- }
- }
-
-
- //---------------------------------------------------------------------------------
- // Purpose: Parses the Admin Group config line setting flags
- //---------------------------------------------------------------------------------
- bool ManiClient::Init(void)
- {
- // Setup the flags
- flag_desc_list.LoadFlags();
- this->AddBuiltInFlags();
-
- FreeClients();
- if (!mani_disable_old_clients.GetBool() && LoadOldStyle())
- {
- // Loaded from old style adminlist.txt etc so write in new file format
- WriteClients();
- if (gpManiDatabase->GetDBEnabled())
- {
- if (this->CreateDBTables(NULL))
- {
- if (this->CreateDBFlags(NULL))
- {
- this->ExportDataToDB(NULL);
- }
- }
- }
- }
-
- FreeClients();
-
- if (gpManiDatabase->GetDBEnabled())
- {
- if (!this->GetClientsFromDatabase(NULL))
- {
- FreeClients();
- LoadClients();
- }
- else
- {
- WriteClients();
- this->SetupUnMasked();
- this->SetupMasked();
- }
- }
- else
- {
- // Load up new style clients
- LoadClients();
- }
-
- flag_desc_list.WriteFlags();
- this->SetupPlayersOnServer();
- LoadIPList();
-
- return true;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Finds any players on the server and creates a link ptr to the client class
- //---------------------------------------------------------------------------------
- void ManiClient::SetupPlayersOnServer(void)
- {
- for (int i = 1; i <= max_players; i++)
- {
- active_client_list[i - 1] = NULL;
- player_t player;
- player.index = i;
- if (!FindPlayerByIndex(&player)) continue;
- if (player.is_bot) continue;
- if (strcmp(player.steam_id, "STEAM_ID_PENDING") == 0) continue;
-
- this->NetworkIDValidated(&player);
- }
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Loads into memory the old style admin flags
- //---------------------------------------------------------------------------------
- bool ManiClient::LoadOldStyle(void)
- {
- FileHandle_t file_handle;
- char base_filename[512];
- char old_base_filename[512];
- char data_in[2048];
- bool loaded_old_style = false;
-
- //check to see if clients.txt exists first - if so, DO NOT RUN THIS
- snprintf(base_filename, sizeof (base_filename), "./cfg/%s/clients.txt", mani_path.GetString());
- file_handle = filesystem->Open (base_filename,"rt",NULL);
- if ( file_handle != NULL )
- {
- filesystem->Close(file_handle);
- return false;
- }
-
-
- //Get admin groups list
- snprintf(base_filename, sizeof (base_filename), "./cfg/%s/admingroups.txt", mani_path.GetString());
- file_handle = filesystem->Open (base_filename,"rt",NULL);
- if (file_handle == NULL)
- {
- // MMsg("Old style admingroups.txt file does not exist, using V1.2+ style\n");
- }
- else
- {
- MMsg("Admin Group list\n");
- while (filesystem->ReadLine (data_in, sizeof(data_in), file_handle) != NULL)
- {
- if (!ParseLine(data_in, true, false))
- {
- // String is empty after parsing
- continue;
- }
-
- OldAddGroup(data_in, ADMIN);
- }
-
- filesystem->Close(file_handle);
-
- snprintf(old_base_filename, sizeof(old_base_filename), "%s.old", base_filename);
- filesystem->RenameFile(base_filename, old_base_filename);
- loaded_old_style = true;
- }
-
- //Get immunity groups list
- snprintf(base_filename, sizeof (base_filename), "./cfg/%s/immunitygroups.txt", mani_path.GetString());
- file_handle = filesystem->Open (base_filename,"rt",NULL);
- if (file_handle == NULL)
- {
- // MMsg("Old style immunitygroups.txt file does not exist, using V1.2+ style\n");
- }
- else
- {
- MMsg("Immunity Group list\n");
- while (filesystem->ReadLine (data_in, sizeof(data_in), file_handle) != NULL)
- {
- if (!ParseLine(data_in, true, false))
- {
- // String is empty after parsing
- continue;
- }
-
- OldAddGroup(data_in, IMMUNITY);
- }
-
- filesystem->Close(file_handle);
-
- snprintf(old_base_filename, sizeof(old_base_filename), "%s.old", base_filename);
- filesystem->RenameFile(base_filename, old_base_filename);
- loaded_old_style = true;
- }
-
- //Get admin list
- snprintf(base_filename, sizeof (base_filename), "./cfg/%s/adminlist.txt", mani_path.GetString());
- file_handle = filesystem->Open (base_filename,"rt",NULL);
- if (file_handle == NULL)
- {
- // MMsg("Old style adminlist.txt file does not exist, using V1.2+ style\n");
- }
- else
- {
- MMsg("Admin steam id list\n");
- while (filesystem->ReadLine (data_in, sizeof(data_in), file_handle) != NULL)
- {
- if (!ParseLine(data_in, true, false))
- {
- // String is empty after parsing
- continue;
- }
-
- old_style_client_t temp_client;
-
- if (!OldAddClient(data_in, &temp_client, true)) continue;
-
- // Client data is okay, add it to client list
- ConvertOldClientToNewClient(&temp_client, true);
- }
-
- filesystem->Close(file_handle);
- snprintf(old_base_filename, sizeof(old_base_filename), "%s.old", base_filename);
- filesystem->RenameFile(base_filename, old_base_filename);
-
- loaded_old_style = true;
- }
-
- //Get immunity list
- snprintf(base_filename, sizeof (base_filename), "./cfg/%s/immunitylist.txt", mani_path.GetString());
- file_handle = filesystem->Open (base_filename,"rt",NULL);
- if (file_handle == NULL)
- {
- // MMsg("Old style immunitylist.txt file does not exist, using V1.2+ style\n");
- }
- else
- {
- MMsg("Immunity list\n");
- while (filesystem->ReadLine (data_in, sizeof(data_in), file_handle) != NULL)
- {
- if (!ParseLine(data_in, true, false))
- {
- // String is empty after parsing
- continue;
- }
-
- old_style_client_t temp_client;
-
- if (!OldAddClient(data_in, &temp_client, false)) continue;
-
- // Client data is okay, add it to client list
- ConvertOldClientToNewClient(&temp_client, false);
- }
-
- filesystem->Close(file_handle);
-
- snprintf(old_base_filename, sizeof(old_base_filename), "%s.old", base_filename);
- filesystem->RenameFile(base_filename, old_base_filename);
- loaded_old_style = true;
- }
-
- // We have to botch in player names here that need to be unqiue
- for (int i = 0; i != (int) c_list.size(); i++)
- {
- // No name set up
- if (gpManiDatabase->GetDBEnabled())
- {
- /* Need unique name !! */
- char new_name[128];
- snprintf(new_name, sizeof(new_name), "Client_%i_%s", i+1,
- gpManiDatabase->GetServerGroupID());
- c_list[i]->SetName(new_name);
- }
- else
- {
- char new_name[128];
- snprintf(new_name, sizeof(new_name), "Client_%i", i+1);
- c_list[i]->SetName(new_name);
-
- }
- }
-
- this->SetupUnMasked();
- this->SetupMasked();
-
- return (loaded_old_style);
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Add the client to an already existing entry or create a new one
- //---------------------------------------------------------------------------------
- void ManiClient::ConvertOldClientToNewClient
- (
- old_style_client_t *old_client_ptr,
- bool is_admin
- )
- {
- ClientPlayer *client_ptr;
- int client_index = -1;
- bool by_steam = false;
- bool by_ip = false;
- bool by_name = false;
-
- // Find existing client record
- client_index = FindClientIndex(old_client_ptr->steam_id);
- if (client_index == -1)
- {
- client_index = FindClientIndex(old_client_ptr->ip_address);
- if (client_index == -1)
- {
- client_index = FindClientIndex(old_client_ptr->name);
- if (client_index != -1)
- {
- by_name = true;
- }
- }
- else
- {
- by_ip = true;
- }
- }
- else
- {
- by_steam = true;
- }
-
- if (client_index == -1)
- {
- // Create new client record as we didn't find one
- MMsg("Adding client *********\n");
- client_ptr = new ClientPlayer;
- c_list.push_back(client_ptr);
- }
- else
- {
- // We found a client so point there
- client_ptr = c_list[client_index];
- MMsg("Found client *********\n");
- }
-
- // Copy core information about player
- if (old_client_ptr->steam_id && !FStrEq(old_client_ptr->steam_id,""))
- {
- if (!by_steam)
- {
- client_ptr->steam_list.Add(old_client_ptr->steam_id);
- }
- }
-
- if (old_client_ptr->ip_address && !FStrEq(old_client_ptr->ip_address,""))
- {
- if (!by_ip)
- {
- client_ptr->ip_address_list.Add(old_client_ptr->ip_address);
- }
- }
-
- if (old_client_ptr->name && !FStrEq(old_client_ptr->name,""))
- {
- if (!by_name)
- {
- client_ptr->nick_list.Add(old_client_ptr->name);
- }
- }
-
- if (old_client_ptr->password && !FStrEq(old_client_ptr->password,""))
- {
- client_ptr->SetPassword(old_client_ptr->password);
- }
-
-
- if (old_client_ptr->group_id && !FStrEq(old_client_ptr->group_id, ""))
- {
- if (is_admin)
- {
- client_ptr->group_list.Add(ADMIN, old_client_ptr->group_id);
- }
- else
- {
- client_ptr->group_list.Add(IMMUNITY, old_client_ptr->group_id);
- }
- }
-
-
- // Handle flags for client
- if (is_admin)
- {
- for (int i = 0; i < MAX_ADMIN_FLAGS; i++)
- {
- if (old_client_ptr->flags[i].enabled)
- {
- client_ptr->personal_flag_list.SetFlag(ADMIN, old_client_ptr->flags[i].flag_name, true);
- }
- }
- }
- else
- {
- for (int i = 0; i < MAX_IMMUNITY_FLAGS; i++)
- {
- if (old_client_ptr->flags[i].enabled)
- {
- client_ptr->personal_flag_list.SetFlag(IMMUNITY, old_client_ptr->flags[i].flag_name, true);
- }
- }
- }
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Free's up admin list memory
- //---------------------------------------------------------------------------------
-
- void ManiClient::FreeClients(void)
- {
- // New free clients section
- for (int i = 0; i != (int) c_list.size(); i++)
- {
- delete c_list[i];
- }
-
- c_list.clear();
- group_list.Kill();
- level_list.Kill();
-
- for (int i = 0; i < MANI_MAX_PLAYERS; i++)
- {
- active_client_list[i] = NULL;
- }
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Sets up admin flags, if you add a new flag it needs to be initialised
- // here !!
- //---------------------------------------------------------------------------------
- bool IsCommandIssuedByServerAdmin( void )
- {
- if ( engine->IsDedicatedServer() && con_command_index > -1 )
- return false;
-
- if ( !engine->IsDedicatedServer() && con_command_index > 0 )
- return false;
-
- return true;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Creates database tables
- //---------------------------------------------------------------------------------
- bool ManiClient::CreateDBTables(player_t *player_ptr)
- {
- ManiMySQL *mani_mysql = new ManiMySQL();
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating DB tables if not existing....");
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClient());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL auto_increment, "
- "name varchar(32) NOT NULL, "
- "password varchar(32) default '', "
- "email varchar(255) default '', "
- "notes varchar(255) default '', "
- "PRIMARY KEY (user_id), "
- "UNIQUE KEY (name) "
- ") ENGINE=MyISAM AUTO_INCREMENT=1",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClient()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBSteam());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s( "
- "user_id mediumint(8) NOT NULL default '0', "
- "steam_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, steam_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBSteam()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBNick());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL default '0', "
- "nick varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, nick) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBNick()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBIP());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL default '0', "
- "ip_address varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, ip_address) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBIP()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBFlag());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "flag_id varchar(20) BINARY NOT NULL default '', "
- "type varchar(32) NOT NULL default '', "
- "description varchar(128) NOT NULL default '', "
- "PRIMARY KEY (flag_id, type) "
- ") ENGINE=MyISAM",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBFlag()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBServer());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "server_id mediumint(8) NOT NULL default '0', "
- "name varchar(128) NOT NULL default '', "
- "ip_address varchar(32) NOT NULL default '', "
- "port mediumint(8) NOT NULL default '0', "
- "mod_name varchar(64) NOT NULL default '', "
- "rcon_password varchar(64) default '', "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (server_id), "
- "UNIQUE KEY (name) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBServer()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBGroup());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "group_id varchar(32) NOT NULL default '', "
- "flag_string text, "
- "type varchar(32) NOT NULL default '', "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (group_id, type, server_group_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBGroup()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientGroup());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL default '0', "
- "group_id varchar(32) NOT NULL default '', "
- "type varchar(32) NOT NULL default '', "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, group_id, type, server_group_id) "
- ") ENGINE=MyISAM",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientGroup()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientFlag());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL default '0', "
- "flag_string text, "
- "type varchar(32) NOT NULL default '', "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, type, server_group_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientFlag()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientLevel());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s( "
- "user_id mediumint(8) NOT NULL default '0', "
- "level_id mediumint(8) NOT NULL default '-1', "
- "type varchar(32) NOT NULL default '', "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (user_id, level_id, type, server_group_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientLevel()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBLevel());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "level_id mediumint(8) NOT NULL default '-1', "
- "type varchar(32) NOT NULL default '', "
- "flag_string text, "
- "server_group_id varchar(32) NOT NULL default '', "
- "PRIMARY KEY (level_id, type, server_group_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBLevel()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientServer());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "user_id mediumint(8) NOT NULL default '0', "
- "server_group_id varchar(32) NOT NULL default '0', "
- "PRIMARY KEY (user_id, server_group_id) "
- ") ENGINE=MyISAM"
- , gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientServer()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Creating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBVersion());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "CREATE TABLE IF NOT EXISTS %s%s ( "
- "version_id varchar(20) NOT NULL)",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBVersion()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Checking %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBVersion());
-
- int row_count;
- if (mani_mysql->ExecuteQuery(player_ptr, &row_count, "SELECT 1 FROM %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBVersion()))
- {
- if (row_count == 0)
- {
- OutputHelpText(GREEN_CHAT, player_ptr, "No rows found, inserting into %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBVersion());
- // No rows so insert one
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT INTO %s%s VALUES ('%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBVersion(),
- PLUGIN_VERSION_ID2))
- {
- delete mani_mysql;
- return false;
- }
- }
- else
- {
- OutputHelpText(GREEN_CHAT, player_ptr, "Row found, updating %s%s", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBVersion());
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "UPDATE %s%s SET version_id = '%s'",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBVersion(),
- PLUGIN_VERSION_ID2))
- {
- delete mani_mysql;
- return false;
- }
- }
- }
- else
- {
- delete mani_mysql;
- return false;
- }
-
- delete mani_mysql;
-
- return true;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Creates flag information in tables
- //---------------------------------------------------------------------------------
- bool ManiClient::CreateDBFlags(player_t *player_ptr)
- {
- ManiMySQL *mani_mysql = new ManiMySQL();
-
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Generating DB access flags if not existing....");
-
- for (const char *c_type = class_type_list.FindFirst(); c_type != NULL; c_type = class_type_list.FindNext())
- {
- const DualStrKey *key_value = NULL;
- for (const char *desc = flag_desc_list.FindFirst(c_type, &key_value); desc != NULL; desc = flag_desc_list.FindNext(c_type, &key_value))
- {
- OutputHelpText(ORANGE_CHAT, player_ptr, "Checking class [%s] flag_id [%s]", c_type, key_value->key2);
- int row_count = 0;
-
- if (!mani_mysql->ExecuteQuery(player_ptr, &row_count, "SELECT f.description "
- "FROM %s%s f "
- "where f.flag_id = '%s' "
- "and f.type = '%s'",
- gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBFlag(),
- key_value->key2, c_type))
- {
- delete mani_mysql;
- return false;
- }
-
- if (row_count == 0)
- {
- OutputHelpText(ORANGE_CHAT, player_ptr, "Inserting class [%s] flag_id [%s]", c_type, key_value->key2);
- // Setup flag record
- if (!mani_mysql->ExecuteQuery(player_ptr, "INSERT INTO %s%s (flag_id, type, description) VALUES ('%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBFlag(),
- key_value->key2,
- c_type,
- desc))
- {
- delete mani_mysql;
- return false;
- }
- }
- else
- {
- mani_mysql->FetchRow();
- if (strcmp(mani_mysql->GetString(0), desc) != 0)
- {
- OutputHelpText(ORANGE_CHAT, player_ptr, "Updating class [%s] flag_id [%s] with new description [%s]", c_type, key_value->key2, desc);
- // Update to the new description
- if (!mani_mysql->ExecuteQuery(player_ptr, "UPDATE %s%s SET description = '%s' WHERE flag_id = '%s' AND type = '%s'",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBFlag(),
- desc,
- key_value->key2,
- c_type))
- {
- delete mani_mysql;
- return false;
- }
- }
- }
- }
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Updating version id..");
-
- mani_mysql->ExecuteQuery(player_ptr,
- "UPDATE %s%s "
- "SET version_id = '%s'",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBVersion(),
- PLUGIN_CORE_VERSION);
-
- delete mani_mysql;
-
- return true;
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Export data in memory to the database
- //---------------------------------------------------------------------------------
- bool ManiClient::ExportDataToDB(player_t *player_ptr)
- {
- char flag_string[2048];
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Exporting data from clients.txt to DB....");
-
- ManiMySQL *mani_mysql = new ManiMySQL();
-
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
-
- // Clean out tables for this server id
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBGroup(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientGroup(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBLevel(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientLevel(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientFlag(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_group_id = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClientServer(), gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_id = %i", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBServer(), gpManiDatabase->GetServerID()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Deleted existing DB data for this server....");
-
- // Do server details
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT INTO %s%s VALUES (%i, '%s', '%s', %i, '%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBServer(),
- gpManiDatabase->GetServerID(),
- gpManiDatabase->GetServerName(),
- gpManiDatabase->GetServerIPAddress(),
- gpManiDatabase->GetServerPort(),
- gpManiDatabase->GetModName(),
- gpManiDatabase->GetRCONPassword(),
- gpManiDatabase->GetServerGroupID()
- ))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Generated server details....");
-
-
- for (const char *c_type = class_type_list.FindFirst(); c_type != NULL; c_type = class_type_list.FindNext())
- {
- const DualStrIntKey *key_value = NULL;
- for (GlobalGroupFlag *g_flag = level_list.FindFirst(c_type, &key_value); g_flag != NULL; g_flag = level_list.FindNext(c_type, &key_value))
- {
- Q_strcpy(flag_string, "");
- if (g_flag->CatFlags(flag_string))
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (level_id, type, flag_string, server_group_id) VALUES (%i, '%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBLevel(),
- key_value->key2,
- key_value->key1,
- flag_string,
- gpManiDatabase->GetServerGroupID()))
-
- {
- delete mani_mysql;
- return false;
- }
- }
- }
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Generated level groups....");
-
- // Do the flag groups next
-
- for (const char *c_type = class_type_list.FindFirst(); c_type != NULL; c_type = class_type_list.FindNext())
- {
- const DualStriKey *key_value = NULL;
- for (GlobalGroupFlag *g_flag = group_list.FindFirst(c_type, &key_value); g_flag != NULL; g_flag = group_list.FindNext(c_type, &key_value))
- {
- Q_strcpy(flag_string, "");
- if (g_flag->CatFlags(flag_string))
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (group_id, flag_string, type, server_group_id) VALUES ('%s', '%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBGroup(),
- key_value->key2,
- flag_string,
- key_value->key1,
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
- }
- }
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Generated DB global groups....");
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Building DB client data for %i clients", (int) c_list.size());
- // Populate client list for players that already exist on the server
- // and generate new clients if necessary with user ids
- for (int i = 0; i != (int) c_list.size(); i ++)
- {
- int row_count;
-
- OutputHelpText(GREEN_CHAT, player_ptr, "%i", (int) c_list.size() - i);
-
- c_list[i]->SetUserID(-1);
-
- if (!mani_mysql->ExecuteQuery(player_ptr,
- &row_count,
- "SELECT user_id FROM %s%s WHERE name = '%s'", gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBClient(), c_list[i]->GetName()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (row_count != 0)
- {
- if (!mani_mysql->FetchRow())
- {
- // Should get at least 1 row
- delete mani_mysql;
- return false;
- }
-
- c_list[i]->SetUserID(mani_mysql->GetInt(0));
- }
- else
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s "
- "(name, password, email, notes) "
- "VALUES "
- "('%s', '%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClient(),
- c_list[i]->GetName(),
- c_list[i]->GetPassword(),
- c_list[i]->GetEmailAddress(),
- c_list[i]->GetNotes()))
- {
- delete mani_mysql;
- return false;
- }
-
- c_list[i]->SetUserID(mani_mysql->GetRowID());
- }
-
- // Setup steam ids
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "DELETE FROM %s%s WHERE user_id = %i",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBSteam(),
- c_list[i]->GetUserID()))
- {
- delete mani_mysql;
- return false;
- }
-
- for (const char *steam_id = c_list[i]->steam_list.FindFirst(); steam_id != NULL; steam_id = c_list[i]->steam_list.FindNext())
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, steam_id) VALUES (%i, '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBSteam(),
- c_list[i]->GetUserID(),
- steam_id))
- {
- delete mani_mysql;
- return false;
- }
- }
-
- // Setup ip addresses
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "DELETE FROM %s%s WHERE user_id = %i",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBIP(),
- c_list[i]->GetUserID()))
- {
- delete mani_mysql;
- return false;
- }
-
- for (const char *ip_address = c_list[i]->ip_address_list.FindFirst(); ip_address != NULL; ip_address = c_list[i]->ip_address_list.FindNext())
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, ip_address) VALUES (%i, '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBIP(),
- c_list[i]->GetUserID(),
- ip_address))
- {
- delete mani_mysql;
- return false;
- }
- }
-
- // Setup nickname ids
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "DELETE FROM %s%s WHERE user_id = %i",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBNick(),
- c_list[i]->GetUserID()))
- {
- delete mani_mysql;
- return false;
- }
-
- for (const char *nick = c_list[i]->nick_list.FindFirst(); nick != NULL; nick = c_list[i]->nick_list.FindNext())
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, nick) VALUES (%i, '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBNick(),
- c_list[i]->GetUserID(),
- nick))
- {
- delete mani_mysql;
- return false;
- }
- }
-
- // Setup client_server record
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT INTO %s%s (user_id, server_group_id) VALUES (%i, '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientServer(),
- c_list[i]->GetUserID(),
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- Q_strcpy(flag_string, "");
-
- // Client personal flags
- // Search through known about flags
- for (const char *c_type = class_type_list.FindFirst(); c_type != NULL; c_type = class_type_list.FindNext())
- {
- if (c_list[i]->personal_flag_list.CatFlags(flag_string, c_type))
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, flag_string, type, server_group_id) VALUES (%i,'%s','%s','%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientFlag(),
- c_list[i]->GetUserID(),
- flag_string,
- c_type,
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
- }
- }
-
- // Do the client_group flags next
- const char *group_id = NULL;
- for (const char *c_type = c_list[i]->group_list.FindFirst(&group_id); c_type != NULL; c_type = c_list[i]->group_list.FindNext(&group_id))
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, group_id, type, server_group_id) VALUES (%i,'%s','%s','%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientGroup(),
- c_list[i]->GetUserID(),
- group_id,
- c_type,
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
- }
-
- // Do the client_level flags next
-
- const char *cl_type = NULL;
- for (int level_id = c_list[i]->level_list.FindFirst(&cl_type); level_id != -99999; level_id = c_list[i]->level_list.FindNext(&cl_type))
- {
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT IGNORE INTO %s%s (user_id, level_id, type, server_group_id) VALUES (%i,%i,'%s','%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBClientLevel(),
- c_list[i]->GetUserID(),
- level_id,
- cl_type,
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
- }
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Clients built on DB");
-
- delete mani_mysql;
-
- return true;
-
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Export server id information
- //---------------------------------------------------------------------------------
- bool ManiClient::UploadServerID(player_t *player_ptr)
- {
- OutputHelpText(GREEN_CHAT, player_ptr, "Exporting data from database.txt to DB....");
- ManiMySQL *mani_mysql = new ManiMySQL();
-
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr, "DELETE FROM %s%s WHERE server_id = %i",
- gpManiDatabase->GetDBTablePrefix(), gpManiDatabase->GetDBTBServer(), gpManiDatabase->GetServerID()))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Deleted existing server information for this server....");
-
- // Do server details
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "INSERT INTO %s%s VALUES (%i, '%s', '%s', %i, '%s', '%s', '%s')",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBServer(),
- gpManiDatabase->GetServerID(),
- gpManiDatabase->GetServerName(),
- gpManiDatabase->GetServerIPAddress(),
- gpManiDatabase->GetServerPort(),
- gpManiDatabase->GetModName(),
- gpManiDatabase->GetRCONPassword(),
- gpManiDatabase->GetServerGroupID()
- ))
- {
- delete mani_mysql;
- return false;
- }
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Generated server details....");
-
- return true;
-
- }
-
- //---------------------------------------------------------------------------------
- // Purpose: Get Client data from database
- //---------------------------------------------------------------------------------
- bool ManiClient::GetClientsFromDatabase(player_t *player_ptr)
- {
- bool found_flag;
- int row_count;
- char flags_string[2048];
-
- // Upgrade the database to V1.2 Beta M functionality
- UpgradeDB1();
-
- OutputHelpText(GREEN_CHAT, player_ptr, "Getting client info from the database....");
-
- ManiMySQL *mani_mysql = new ManiMySQL();
-
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
-
- if (!mani_mysql->ExecuteQuery(player_ptr,
- "UPDATE %s%s SET server_group_id = '%s' WHERE server_id = %i",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBServer(),
- gpManiDatabase->GetServerGroupID(),
- gpManiDatabase->GetServerID()))
- {
- delete mani_mysql;
- mani_mysql = new ManiMySQL();
- if (!mani_mysql->Init(player_ptr))
- {
- delete mani_mysql;
- return false;
- }
- }
-
-
- // Get admin groups
- if (!mani_mysql->ExecuteQuery(player_ptr,
- &row_count,
- "SELECT g.group_id, g.flag_string, g.type "
- "FROM %s%s g "
- "WHERE g.server_group_id = '%s' ",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBGroup(),
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (row_count != 0)
- {
- // Found rows
- while (mani_mysql->FetchRow())
- {
- char *group_id = mani_mysql->GetString(0);
- Q_strcpy(flags_string, mani_mysql->GetString(1));
- char *class_type = mani_mysql->GetString(2);
-
- int flag_index = 0;
- for (;;)
- {
- char *flag_id = SplitFlagString(flags_string, &flag_index);
- if (flag_id == NULL)
- {
- break;
- }
-
- if (flag_desc_list.IsValidFlag(class_type, flag_id))
- {
- // Create/Update group/level
- GlobalGroupFlag *g_flag = group_list.AddGroup(class_type, group_id);
- if (g_flag)
- {
- g_flag->SetFlag(flag_id, true);
- }
- }
- }
- }
- }
-
- // Get admin levels
- if (!mani_mysql->ExecuteQuery(player_ptr,
- &row_count,
- "SELECT l.level_id, l.flag_string, l.type "
- "FROM %s%s l "
- "WHERE l.server_group_id = '%s' "
- "ORDER BY l.level_id",
- gpManiDatabase->GetDBTablePrefix(),
- gpManiDatabase->GetDBTBLevel(),
- gpManiDatabase->GetServerGroupID()))
- {
- delete mani_mysql;
- return false;
- }
-
- if (row_count != 0)
- {
- // Found rows
- while (mani_mysql->FetchRow())
- {
- char *level_id = mani_mysql->GetString(0);
- Q_strcpy(flags_string, mani_mysql->GetString(1));
- char *class_type = mani_mysql->GetString(2);
-
- int flag_index = 0;
- for (;;)
- {
- char *flag_id = SplitFlagString(flags_string, &flag_index);
- if (flag_id == NULL)
- {
- break;
- }
-
- if (flag_desc_list.IsValidFlag(class_type, flag_id))
- {
- // Create/Update group/level
- GlobalGroupFlag *g_flag = level_list.AddGroup(class_type, atoi(level_id));
- if (g_flag)
- {
- g_flag->SetFlag(flag_id, true);
- }
- }
- }
- }
- }
-
- // Get clients for this server
- // Ridiculous search that brings back too many rows but ultimately
- // is faster than doing all the seperate selects per client
- // to do the same thing :(
-
- OutputHelpText(GREEN_CHAT, player_ptr, "SQL server version [%s]", mani_mysql->GetServerVersion());
- OutputHelpText(GREEN_CHAT, player_ptr, "Major [%i] Minor [%i] Issue [%i]", mani_mysql->GetMajor(), mani_mysql->GetMinor(), mani_mysql->Ge…
Large files files are truncated, but you can click here to view the full file