void DS::AuthServer_Add(DS::SocketHandle client) { #ifdef DEBUG if (s_commdebug) printf("Connecting AUTH on %s\n", DS::SockIpAddress(client).c_str()); #endif std::thread threadh(&wk_authWorker, client); threadh.detach(); }
void DS::GateKeeper_Add(DS::SocketHandle client) { #ifdef DEBUG if (s_commdebug) printf("Connecting GATE on %s\n", DS::SockIpAddress(client).c_str()); #endif std::thread threadh(&wk_gateKeeper, client); threadh.detach(); }
GameHost_Private* start_game_host(uint32_t ageMcpId) { PGconn* postgres = PQconnectdb(DS::String::Format( "host='%s' port='%s' user='******' password='******' dbname='%s'", DS::Settings::DbHostname(), DS::Settings::DbPort(), DS::Settings::DbUsername(), DS::Settings::DbPassword(), DS::Settings::DbDbaseName()).c_str()); if (PQstatus(postgres) != CONNECTION_OK) { fprintf(stderr, "Error connecting to postgres: %s", PQerrorMessage(postgres)); PQfinish(postgres); return 0; } PostgresStrings<1> parms; parms.set(0, ageMcpId); PGresult* result = PQexecParams(postgres, "SELECT \"AgeUuid\", \"AgeFilename\", \"AgeIdx\", \"SdlIdx\", \"Temporary\"" " FROM game.\"Servers\" WHERE idx=$1", 1, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(postgres)); PQclear(result); PQfinish(postgres); return 0; } if (PQntuples(result) == 0) { fprintf(stderr, "[Game] Age MCP %u not found\n", ageMcpId); PQclear(result); PQfinish(postgres); return 0; } else { DS_DASSERT(PQntuples(result) == 1); GameHost_Private* host = new GameHost_Private(); host->m_instanceId = PQgetvalue(result, 0, 0); host->m_ageFilename = PQgetvalue(result, 0, 1); host->m_ageIdx = strtoul(PQgetvalue(result, 0, 2), 0, 10); host->m_gameMaster = 0; host->m_serverIdx = ageMcpId; host->m_postgres = postgres; host->m_temp = strcmp("t", PQgetvalue(result, 0, 4)) == 0; // Fetch the age states Auth_FetchSDL sdlFetch; AuthClient_Private fakeClient; sdlFetch.m_client = &fakeClient; sdlFetch.m_ageFilename = host->m_ageFilename; sdlFetch.m_sdlNodeId = strtoul(PQgetvalue(result, 0, 3), 0, 10); PQclear(result); s_authChannel.putMessage(e_AuthFetchSDL, reinterpret_cast<void*>(&sdlFetch)); DS::FifoMessage reply = fakeClient.m_channel.getMessage(); if (reply.m_messageType != DS::e_NetSuccess) { fputs("[Game] Error fetching Age SDL\n", stderr); PQfinish(postgres); delete host; return 0; } host->m_sdlIdx = sdlFetch.m_sdlNodeId; host->m_globalState = sdlFetch.m_globalState; // Load the local state and see if it needs to be updated try { host->m_localState = SDL::State::FromBlob(sdlFetch.m_localState); } catch (DS::EofException&) { fprintf(stderr, "[SDL] Error parsing Age SDL state for %s\n", host->m_ageFilename.c_str()); PQfinish(postgres); delete host; return 0; } if (host->m_localState.update()) { DS::Blob local = host->m_localState.toBlob(); dm_local_sdl_update(host, local); host->m_ageSdlHook = SDL::State::FromBlob(local); } else { host->m_ageSdlHook = SDL::State::FromBlob(sdlFetch.m_localState); } host->m_ageSdlHook.merge(host->m_globalState); s_gameHostMutex.lock(); s_gameHosts[ageMcpId] = host; s_gameHostMutex.unlock(); // Fetch initial server state PostgresStrings<1> parms; parms.set(0, host->m_serverIdx); PGresult* result = PQexecParams(host->m_postgres, "SELECT \"Descriptor\", \"ObjectKey\", \"SdlBlob\"" " FROM game.\"AgeStates\" WHERE \"ServerIdx\"=$1", 1, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(host->m_postgres)); } else { int count = PQntuples(result); for (int i=0; i<count; ++i) { DS::BlobStream bsObject(DS::Base64Decode(PQgetvalue(result, i, 1))); DS::Blob sdlblob = DS::Base64Decode(PQgetvalue(result, i, 2)); MOUL::Uoid key; key.read(&bsObject); try { SDL::State state = SDL::State::FromBlob(sdlblob); state.update(); GameState gs; gs.m_isAvatar = false; gs.m_persist = true; gs.m_state = state; host->m_states[key][PQgetvalue(result, i, 0)] = gs; } catch (DS::EofException) { fprintf(stderr, "[SDL] Error parsing state %s for [%04X]%s\n", PQgetvalue(result, i, 0), key.m_type, key.m_name.c_str()); } } } PQclear(result); std::thread threadh(&dm_gameHost, host); threadh.detach(); return host; } }
void DS::FileServer_Add(DS::SocketHandle client) { std::thread threadh(&wk_fileServ, client); threadh.detach(); }