Skip to content

Commit 4e69786

Browse files
author
Shauren
committed
Core/World: Set realm status as invalid during startup and online when initialized
--HG-- branch : trunk
1 parent f0db539 commit 4e69786

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

src/server/worldserver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ include_directories(
131131
${CMAKE_SOURCE_DIR}/src/server/game/Tools
132132
${CMAKE_SOURCE_DIR}/src/server/game/Weather
133133
${CMAKE_SOURCE_DIR}/src/server/game/World
134+
${CMAKE_SOURCE_DIR}/src/server/authserver/Server
134135
${CMAKE_CURRENT_SOURCE_DIR}
135136
${CMAKE_CURRENT_SOURCE_DIR}/CommandLine
136137
${CMAKE_CURRENT_SOURCE_DIR}/RemoteAccess

src/server/worldserver/Master.cpp

+45-41
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "TCSoap.h"
4141
#include "Timer.h"
4242
#include "Util.h"
43+
#include "AuthSocket.h"
4344

4445
#include "BigNumber.h"
4546

@@ -122,44 +123,47 @@ int Master::Run()
122123
BigNumber seed1;
123124
seed1.SetRand(16 * 8);
124125

125-
sLog->outString( "%s (core-daemon)", _FULLVERSION );
126-
sLog->outString( "<Ctrl-C> to stop.\n" );
126+
sLog->outString("%s (core-daemon)", _FULLVERSION);
127+
sLog->outString("<Ctrl-C> to stop.\n");
127128

128-
sLog->outString( " ______ __");
129-
sLog->outString( "/\\__ _\\ __ __/\\ \\__");
130-
sLog->outString( "\\/_/\\ \\/ _ __ /\\_\\ ___ /\\_\\ \\ ,_\\ __ __");
131-
sLog->outString( " \\ \\ \\/\\`'__\\/\\ \\ /' _ `\\/\\ \\ \\ \\/ /\\ \\/\\ \\");
132-
sLog->outString( " \\ \\ \\ \\ \\/ \\ \\ \\/\\ \\/\\ \\ \\ \\ \\ \\_\\ \\ \\_\\ \\");
133-
sLog->outString( " \\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\_\\ \\_\\ \\__\\\\/`____ \\");
134-
sLog->outString( " \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\");
135-
sLog->outString( " C O R E /\\___/");
136-
sLog->outString( "http://TrinityCore.org \\/__/\n");
129+
sLog->outString(" ______ __");
130+
sLog->outString("/\\__ _\\ __ __/\\ \\__");
131+
sLog->outString("\\/_/\\ \\/ _ __ /\\_\\ ___ /\\_\\ \\ ,_\\ __ __");
132+
sLog->outString(" \\ \\ \\/\\`'__\\/\\ \\ /' _ `\\/\\ \\ \\ \\/ /\\ \\/\\ \\");
133+
sLog->outString(" \\ \\ \\ \\ \\/ \\ \\ \\/\\ \\/\\ \\ \\ \\ \\ \\_\\ \\ \\_\\ \\");
134+
sLog->outString(" \\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\_\\ \\_\\ \\__\\\\/`____ \\");
135+
sLog->outString(" \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\");
136+
sLog->outString(" C O R E /\\___/");
137+
sLog->outString("http://TrinityCore.org \\/__/\n");
137138

138139
#ifdef USE_SFMT_FOR_RNG
139-
sLog->outString( "\n");
140-
sLog->outString( "SFMT has been enabled as the random number generator, if worldserver");
141-
sLog->outString( "freezes or crashes randomly, first, try disabling SFMT in CMAKE configuration");
142-
sLog->outString( "\n");
140+
sLog->outString("\n");
141+
sLog->outString("SFMT has been enabled as the random number generator, if worldserver");
142+
sLog->outString("freezes or crashes randomly, first, try disabling SFMT in CMAKE configuration");
143+
sLog->outString("\n");
143144
#endif //USE_SFMT_FOR_RNG
144145

145146
/// worldd PID file creation
146147
std::string pidfile = sConfig->GetStringDefault("PidFile", "");
147-
if(!pidfile.empty())
148+
if (!pidfile.empty())
148149
{
149150
uint32 pid = CreatePIDFile(pidfile);
150-
if( !pid )
151+
if (!pid)
151152
{
152-
sLog->outError( "Cannot create PID file %s.\n", pidfile.c_str() );
153+
sLog->outError("Cannot create PID file %s.\n", pidfile.c_str());
153154
return 1;
154155
}
155156

156-
sLog->outString( "Daemon PID: %u\n", pid );
157+
sLog->outString("Daemon PID: %u\n", pid);
157158
}
158159

159160
///- Start the databases
160161
if (!_StartDB())
161162
return 1;
162163

164+
// set server offline (not connectable)
165+
LoginDatabase.DirectPExecute("UPDATE realmlist SET color = (color & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
166+
163167
///- Initialize the World
164168
sWorld->SetInitialWorldSettings();
165169

@@ -183,9 +187,6 @@ int Master::Run()
183187
ACE_Based::Thread world_thread(new WorldRunnable);
184188
world_thread.setPriority(ACE_Based::Highest);
185189

186-
// set server online
187-
LoginDatabase.PExecute("UPDATE realmlist SET color = 0, population = 0 WHERE id = '%d'",realmID);
188-
189190
ACE_Based::Thread* cliThread = NULL;
190191

191192
#ifdef _WIN32
@@ -206,34 +207,34 @@ int Master::Run()
206207
HANDLE hProcess = GetCurrentProcess();
207208

208209
uint32 Aff = sConfig->GetIntDefault("UseProcessors", 0);
209-
if(Aff > 0)
210+
if (Aff > 0)
210211
{
211212
ULONG_PTR appAff;
212213
ULONG_PTR sysAff;
213214

214-
if(GetProcessAffinityMask(hProcess,&appAff,&sysAff))
215+
if (GetProcessAffinityMask(hProcess,&appAff,&sysAff))
215216
{
216217
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
217218

218-
if(!curAff )
219+
if (!curAff)
219220
{
220221
sLog->outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for Trinityd. Accessible processors bitmask (hex): %x",Aff,appAff);
221222
}
222223
else
223224
{
224-
if(SetProcessAffinityMask(hProcess,curAff))
225+
if (SetProcessAffinityMask(hProcess,curAff))
225226
sLog->outString("Using processors (bitmask, hex): %x", curAff);
226227
else
227-
sLog->outError("Can't set used processors (hex): %x",curAff);
228+
sLog->outError("Can't set used processors (hex): %x", curAff);
228229
}
229230
}
230231
sLog->outString("");
231232
}
232233

233234
bool Prio = sConfig->GetBoolDefault("ProcessPriority", false);
234235

235-
// if(Prio && (m_ServiceStatus == -1)/* need set to default process priority class in service mode*/)
236-
if(Prio)
236+
//if (Prio && (m_ServiceStatus == -1) /* need set to default process priority class in service mode*/)
237+
if (Prio)
237238
{
238239
if(SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
239240
sLog->outString("TrinityCore process priority class set to HIGH");
@@ -246,7 +247,7 @@ int Master::Run()
246247
//Start soap serving thread
247248
ACE_Based::Thread* soap_thread = NULL;
248249

249-
if(sConfig->GetBoolDefault("SOAP.Enabled", false))
250+
if (sConfig->GetBoolDefault("SOAP.Enabled", false))
250251
{
251252
TCSoapRunnable *runnable = new TCSoapRunnable();
252253
runnable->setListenArguments(sConfig->GetStringDefault("SOAP.IP", "127.0.0.1"), sConfig->GetIntDefault("SOAP.Port", 7878));
@@ -257,7 +258,7 @@ int Master::Run()
257258
realCurrTime = realPrevTime = getMSTime();
258259

259260
///- Start up freeze catcher thread
260-
if(uint32 freeze_delay = sConfig->GetIntDefault("MaxCoreStuckTime", 0))
261+
if (uint32 freeze_delay = sConfig->GetIntDefault("MaxCoreStuckTime", 0))
261262
{
262263
FreezeDetectorRunnable *fdr = new FreezeDetectorRunnable();
263264
fdr->SetDelayTime(freeze_delay*1000);
@@ -267,31 +268,34 @@ int Master::Run()
267268

268269
///- Launch the world listener socket
269270
uint16 wsport = sWorld->getIntConfig(CONFIG_PORT_WORLD);
270-
std::string bind_ip = sConfig->GetStringDefault ("BindIP", "0.0.0.0");
271+
std::string bind_ip = sConfig->GetStringDefault("BindIP", "0.0.0.0");
271272

272-
if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1)
273+
if (sWorldSocketMgr->StartNetwork(wsport, bind_ip.c_str ()) == -1)
273274
{
274275
sLog->outError ("Failed to start network");
275276
World::StopNow(ERROR_EXIT_CODE);
276277
// go down and shutdown the server
277278
}
278279

279-
sWorldSocketMgr->Wait ();
280+
// set server online (allow connecting now)
281+
LoginDatabase.DirectPExecute("UPDATE realmlist SET color = color & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_INVALID, realmID);
282+
283+
sWorldSocketMgr->Wait();
280284

281-
if(soap_thread)
285+
if (soap_thread)
282286
{
283-
soap_thread->wait();
284-
soap_thread->destroy();
285-
delete soap_thread;
287+
soap_thread->wait();
288+
soap_thread->destroy();
289+
delete soap_thread;
286290
}
287291

288292
// set server offline
289-
LoginDatabase.PExecute("UPDATE realmlist SET color = 2 WHERE id = '%d'",realmID);
293+
LoginDatabase.PExecute("UPDATE realmlist SET color = color | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realmID);
290294

291295
// when the main thread closes the singletons get unloaded
292296
// since worldrunnable uses them, it will crash if unloaded after master
293297
world_thread.wait();
294-
rar_thread.wait ();
298+
rar_thread.wait();
295299

296300
///- Clean database before leaving
297301
clearOnlineAccounts();
@@ -301,7 +305,7 @@ int Master::Run()
301305
WorldDatabase.Close();
302306
LoginDatabase.Close();
303307

304-
sLog->outString( "Halting process..." );
308+
sLog->outString("Halting process...");
305309

306310
if (cliThread)
307311
{

0 commit comments

Comments
 (0)