|
@@ -89,20 +89,10 @@ LoginServer::LoginServer(const char* iAddress, int16 iPort) {
|
|
|
statusupdate_timer = new Timer(LoginServer_StatusUpdateInterval);
|
|
|
tcpc = new TCPConnection(false);
|
|
|
pTryReconnect = true;
|
|
|
- try_auto_update = true;
|
|
|
- updates_always = false;
|
|
|
- updates_verbose = false;
|
|
|
- updates_auto_data = false;
|
|
|
- updates_ask = false;
|
|
|
minLockedStatus = 100;
|
|
|
maxPlayers = -1;
|
|
|
minGameFullStatus = 100;
|
|
|
- update_server_verified = false;
|
|
|
last_checked_time = 0;
|
|
|
- UpdateServerPort = 0;
|
|
|
- UpdateServerIP = 0;
|
|
|
- update_server_completed = false;
|
|
|
- data_waiting = 0;
|
|
|
zone_updates = 0;
|
|
|
loginEquip_updates = 0;
|
|
|
}
|
|
@@ -211,29 +201,6 @@ bool LoginServer::Process() {
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
- case ServerOP_GetTableData:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): ServerOP_GetTableData", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- uchar* tmp = new uchar[pack->size];
|
|
|
- memcpy(tmp, pack->pBuffer, pack->size);
|
|
|
- data_updates_waiting.push_back(tmp);
|
|
|
- break;
|
|
|
- }
|
|
|
- case ServerOP_GetTableQuery:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): ServerOP_GetTableQuery", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- uchar* tmp = new uchar[pack->size];
|
|
|
- memcpy(tmp, pack->pBuffer, pack->size);
|
|
|
- table_updates_waiting.push_back(tmp);
|
|
|
- break;
|
|
|
- }
|
|
|
- case ServerOP_GetLatestTables:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): ServerOP_GetLatestTables", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- data_waiting = new uchar[pack->size];
|
|
|
- memcpy(data_waiting, pack->pBuffer, pack->size);
|
|
|
- break;
|
|
|
- }
|
|
|
|
|
|
// Push Character Select "item appearances" to login_equipment table
|
|
|
case ServerOP_LoginEquipment:{
|
|
@@ -422,24 +389,6 @@ bool LoginServer::Process() {
|
|
|
database.ResetDatabase();
|
|
|
break;
|
|
|
}
|
|
|
- case UpdateServerOP_Verified:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): UpdateServerOP_Verified", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- update_server_verified = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- case UpdateServerOP_DisplayMsg:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): UpdateServerOP_DisplayMsg", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- LogWrite(WORLD__WARNING, 0, "World", "\t%s", pack->pBuffer);
|
|
|
- break;
|
|
|
- }
|
|
|
- case UpdateServerOP_Completed:{
|
|
|
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): UpdateServerOP_Completed", pack->opcode, pack->opcode);
|
|
|
-
|
|
|
- update_server_completed = true;
|
|
|
- break;
|
|
|
- }
|
|
|
|
|
|
default:
|
|
|
{
|
|
@@ -494,337 +443,7 @@ void LoginServer::InitLoginServerVariables()
|
|
|
minGameFullStatus = rule_manager.GetGlobalRule(R_World, MaxPlayersOverrideStatus)->GetSInt16();
|
|
|
}
|
|
|
|
|
|
-void LoginServer::ProcessDataUpdate(uchar* data){
|
|
|
- TableDataQuery data_query;
|
|
|
- TableQuery table_queries;
|
|
|
- data_query.DeSerialize(data);
|
|
|
- string query;
|
|
|
-
|
|
|
- for(int32 i=0;i<data_query.num_queries;i++)
|
|
|
- {
|
|
|
- query = string("replace into ").append(data_query.tablename).append(" ");
|
|
|
- query.append(data_query.columns).append(" values(").append(data_query.queries[i]->query).append(")\0");
|
|
|
- char* new_query = new char[query.length() + 1];
|
|
|
- memset(new_query, 0, query.length() + 1);
|
|
|
- memcpy(new_query, query.c_str(), query.length());
|
|
|
- table_queries.AddQuery(new_query);
|
|
|
- }
|
|
|
-
|
|
|
- strcpy(table_queries.tablename, data_query.tablename);
|
|
|
- table_queries.latest_version = data_query.version;
|
|
|
- string queries = table_queries.GetQueriesString();
|
|
|
- char answer = 0;
|
|
|
-
|
|
|
- if(UpdatesAsk() || UpdatesVerbose())
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "Pending Queries:\n%s", queries.c_str());
|
|
|
-
|
|
|
- if(!UpdatesAuto() && UpdatesAsk())
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "Update to the latest data version? ([Y]es, [N]o, [A]ll)");
|
|
|
- cin >> answer;
|
|
|
- if(toupper(answer) == 'A')
|
|
|
- UpdatesAuto(true);
|
|
|
- }
|
|
|
- if(UpdatesAuto() || (answer && toupper(answer) == 'Y'))
|
|
|
- {
|
|
|
- bool success = database.RunDatabaseQueries(&table_queries, false, true);
|
|
|
- string table = string(data_query.tablename);
|
|
|
- if(table != last_data_update_table)
|
|
|
- {
|
|
|
- if(success)
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "\tData Updated: '%s' = SUCCESS!", data_query.tablename);
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "Data Updated: '%s' = FAILED!", data_query.tablename);
|
|
|
-
|
|
|
- last_data_update_table = table;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void LoginServer::ProcessTableUpdate(uchar* data) {
|
|
|
- TableQuery table_query;
|
|
|
- table_query.DeSerialize(data);
|
|
|
- string queries = table_query.GetQueriesString();
|
|
|
- char answer = 0;
|
|
|
- if(UpdatesAsk() || UpdatesVerbose())
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "\tUpdate Found for '%s'!", table_query.tablename);
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "\tNew Version: %i", table_query.latest_version);
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "\tYour Version: %i", table_query.your_version);
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "Pending Query:\n%s", queries.c_str());
|
|
|
- }
|
|
|
- if(!UpdatesAuto() && UpdatesAsk())
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "Update to the latest table version? ([Y]es, [N]o, [A]ll)");
|
|
|
- cin >> answer;
|
|
|
- if(toupper(answer) == 'A')
|
|
|
- UpdatesAuto(true);
|
|
|
- }
|
|
|
- if(UpdatesAuto() || (answer && toupper(answer) == 'Y'))
|
|
|
- {
|
|
|
- bool success = database.RunDatabaseQueries(&table_query, false);
|
|
|
- if(success)
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "\tUpdate Table: '%s' = SUCCESS!", table_query.tablename);
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "Update Table: '%s' = FAILED!", table_query.tablename);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-int32 LoginServer::ProcessTableUpdates(uchar* data) {
|
|
|
- int32 ret = 0;
|
|
|
- /*LatestTableVersions table_versions;
|
|
|
- table_versions.DeSerialize(data);
|
|
|
- int32 total_tables = table_versions.GetTotalTables();
|
|
|
-
|
|
|
- int32 max_version = CURRENT_DATABASE_MAJORVERSION*100 + CURRENT_DATABASE_MINORVERSION;
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Max Version: %i", max_version);
|
|
|
-
|
|
|
- vector<ServerPacket*> packet_requests;
|
|
|
- ServerPacket* outpack = 0;
|
|
|
- for(int32 i=0;i<total_tables;i++){
|
|
|
- float version = database.CheckTableVersions(table_versions.GetTable(i).name);
|
|
|
- if( (version < table_versions.GetTable(i).version) )
|
|
|
- {
|
|
|
- outpack = new ServerPacket(ServerOP_GetTableQuery, sizeof(TableVersion));
|
|
|
- TableVersion* out_version = (TableVersion*)outpack->pBuffer;
|
|
|
- strcpy(out_version->name, table_versions.GetTable(i).name);
|
|
|
- out_version->max_table_version = max_version;
|
|
|
- out_version->version = (int32)version;
|
|
|
- out_version->last = 0;
|
|
|
- packet_requests.push_back(outpack);
|
|
|
- ret++;
|
|
|
- }
|
|
|
- }
|
|
|
- if( ret )
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Found Table Updates!");
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--No Table Updates, continuing...");
|
|
|
-
|
|
|
- int32 total_packets = packet_requests.size();
|
|
|
- for(int32 i=0;i<total_packets;i++)
|
|
|
- {
|
|
|
- outpack = packet_requests[i];
|
|
|
- if((i+1) == total_packets)
|
|
|
- {
|
|
|
- TableVersion* out_version = (TableVersion*)outpack->pBuffer;
|
|
|
- out_version->last = 1;
|
|
|
- }
|
|
|
- SendPacket(outpack);
|
|
|
- safe_delete(outpack);
|
|
|
- }*/
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-int32 LoginServer::ProcessDataUpdates(uchar* data) {
|
|
|
- int32 ret = 0;
|
|
|
- /*LatestTableVersions table_versions;
|
|
|
- table_versions.DeSerialize(data);
|
|
|
- int32 total_tables = table_versions.GetTotalTables();
|
|
|
- vector<ServerPacket*> packet_requests;
|
|
|
- ServerPacket* outpack = 0;
|
|
|
- for(int32 i=0;i<total_tables;i++){
|
|
|
- if(UpdatesAutoData()){
|
|
|
- float version = database.GetLatestDataTableVersion(table_versions.GetTable(i).name);
|
|
|
- if(version >= 0 && version < table_versions.GetTable(i).data_version )
|
|
|
- {
|
|
|
- ServerPacket* outpack = new ServerPacket(ServerOP_GetTableData, sizeof(TableVersion));
|
|
|
- TableVersion* out_version = (TableVersion*)outpack->pBuffer;
|
|
|
- strcpy(out_version->name, table_versions.GetTable(i).name);
|
|
|
- out_version->max_data_version = CURRENT_DATABASE_MAJORVERSION*100 + CURRENT_DATABASE_MINORVERSION;
|
|
|
- out_version->data_version = (sint32)version;
|
|
|
- out_version->last = 0;
|
|
|
- memset(out_version->column_names, 0, 1000);
|
|
|
- string columns = database.GetColumnNames(out_version->name);
|
|
|
- if(columns.length() > 1)
|
|
|
- strcpy(out_version->column_names, columns.c_str());
|
|
|
- packet_requests.push_back(outpack);
|
|
|
- ret++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if( ret )
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Found Data Updates!");
|
|
|
-
|
|
|
- int32 total_packets = packet_requests.size();
|
|
|
- for(int32 i=0;i<total_packets;i++)
|
|
|
- {
|
|
|
- outpack = packet_requests[i];
|
|
|
- if((i+1) == total_packets)
|
|
|
- {
|
|
|
- TableVersion* out_version = (TableVersion*)outpack->pBuffer;
|
|
|
- out_version->last = 1;
|
|
|
- }
|
|
|
- SendPacket(outpack);
|
|
|
- safe_delete(outpack);
|
|
|
- }*/
|
|
|
- return ret;
|
|
|
-}
|
|
|
|
|
|
-bool LoginServer::CheckAndWait(Timer* timer){
|
|
|
- Timer::SetCurrentTime();
|
|
|
- if(timer->Check(false)){
|
|
|
- if(timer->GetDuration() == 5000){
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "Please wait...");
|
|
|
- timer->SetTimer(25000);
|
|
|
- timer->Start();
|
|
|
- }
|
|
|
- else
|
|
|
- return false;
|
|
|
- }
|
|
|
- Sleep(10);
|
|
|
- if(!loginserver.Process())
|
|
|
- tcpc->Disconnect();
|
|
|
- return Connected();
|
|
|
-}
|
|
|
-
|
|
|
-bool LoginServer::ConnectToUpdateServer(const char* iAddress, int16 iPort)
|
|
|
-{
|
|
|
- if(!try_auto_update)
|
|
|
- return true;
|
|
|
-
|
|
|
- char errbuf[TCPConnection_ErrorBufferSize];
|
|
|
- memset(errbuf, 0, TCPConnection_ErrorBufferSize);
|
|
|
-
|
|
|
- if (iAddress == 0)
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "PatchServer::ConnectToUpdateServer: address == 0");
|
|
|
- return false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if ((UpdateServerIP = ResolveIP(iAddress, errbuf)) == 0)
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "LoginServer::ConnectToUpdateServer: Resolving IP address: '%s'", errbuf[0] == '\0' ? errbuf : " ");
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (iPort != 0)
|
|
|
- UpdateServerPort = iPort;
|
|
|
-
|
|
|
- if (UpdateServerIP == 0 || UpdateServerPort == 0)
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "PatchServer::ConnectToUpdateServer: Connect info incomplete, cannot connect.");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (tcpc->Connect(UpdateServerIP, UpdateServerPort, errbuf))
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "-Connected to Update Server: %s:%i", iAddress, UpdateServerPort);
|
|
|
- SendInfo();
|
|
|
-
|
|
|
- //wait for a max of 30 seconds to be verified by patcher
|
|
|
- //display a message at 5 seconds
|
|
|
- Timer waitTimer(5000);
|
|
|
- waitTimer.Start();
|
|
|
-
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "-Checking for updates.");
|
|
|
- GetLatestTables();
|
|
|
-
|
|
|
- while(CheckAndWait(&waitTimer) && !update_server_verified);
|
|
|
- database.CheckVersionTable();
|
|
|
-
|
|
|
- if(!update_server_verified)
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "Error while getting updates!");
|
|
|
-
|
|
|
- if(update_server_verified)
|
|
|
- {
|
|
|
- update_server_completed = false;
|
|
|
- waitTimer.SetTimer(5000);
|
|
|
- waitTimer.Start();
|
|
|
-
|
|
|
- while(CheckAndWait(&waitTimer) && !data_waiting);
|
|
|
-
|
|
|
- if(data_waiting)
|
|
|
- {
|
|
|
- int32 requests = ProcessTableUpdates(data_waiting);
|
|
|
-
|
|
|
- if(requests > 0)
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Found Table Updates.");
|
|
|
-
|
|
|
- uchar* data = 0;
|
|
|
- waitTimer.SetTimer(30000);
|
|
|
- waitTimer.Start();
|
|
|
-
|
|
|
- if(requests > 0)
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Processing Table Updates.");
|
|
|
- database.DisableConstraints();
|
|
|
- deque<uchar*> alter_table_updates_waiting;
|
|
|
-
|
|
|
- while((CheckAndWait(&waitTimer) && !update_server_completed) || table_updates_waiting.size() > 0)
|
|
|
- {
|
|
|
- if(table_updates_waiting.size() > 0)
|
|
|
- {
|
|
|
- data = table_updates_waiting.front();
|
|
|
- table_updates_waiting.pop_front();
|
|
|
- ProcessTableUpdate(data);
|
|
|
- safe_delete(data);
|
|
|
- waitTimer.SetTimer(30000);
|
|
|
- waitTimer.Start();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!CheckAndWait(&waitTimer))
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "Timeout waiting for updates to complete! Try again later.");
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Table Update complete.");
|
|
|
-
|
|
|
- database.EnableConstraints();
|
|
|
- }
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "-No changes to DB Schema...");
|
|
|
-
|
|
|
- requests = ProcessDataUpdates(data_waiting);
|
|
|
-
|
|
|
- if(requests > 0)
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Processing Data Updates.");
|
|
|
- LogWrite(INIT__PATCHER_WARNING, 0, "Patcher", "** Data Updates are SLOW! Do not abort! **");
|
|
|
-
|
|
|
- database.DisableConstraints();
|
|
|
-
|
|
|
- deque<uchar*> alter_table_updates_waiting;
|
|
|
- int32 count = 0;
|
|
|
-
|
|
|
- while((CheckAndWait(&waitTimer) && count < requests) || data_updates_waiting.size() > 0)
|
|
|
- {
|
|
|
- if(data_updates_waiting.size() > 0)
|
|
|
- {
|
|
|
- data = data_updates_waiting.front();
|
|
|
- data_updates_waiting.pop_front();
|
|
|
- ProcessDataUpdate(data);
|
|
|
- count++;
|
|
|
- safe_delete_array(data);
|
|
|
- waitTimer.SetTimer(30000);
|
|
|
- waitTimer.Start();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!CheckAndWait(&waitTimer))
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "Timeout waiting for updates to complete! Try again later.");
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "--Data Updates complete.");
|
|
|
-
|
|
|
- database.EnableConstraints();
|
|
|
- }
|
|
|
- else
|
|
|
- LogWrite(INIT__PATCHER_DEBUG, 0, "Patcher", "-No changes to DB Data...");
|
|
|
-
|
|
|
- safe_delete_array(data_waiting);
|
|
|
- }
|
|
|
- try_auto_update = false;
|
|
|
- }
|
|
|
-
|
|
|
- tcpc->Disconnect();
|
|
|
- return update_server_verified;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogWrite(INIT__PATCHER_ERROR, 0, "Patcher", "PatchServer::ConnectToUpdateServer: '%s'", errbuf[0] == '\0' ? errbuf : " ");
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
bool LoginServer::Connect(const char* iAddress, int16 iPort) {
|
|
|
if(!pTryReconnect)
|