Example #1
0
int CGameServer::ConnectToMasterServer()
{
  serverNet.Initialize(this, "serverNet");
  serverNet.CreateClient();
  
  const char* hostaddr = cfg_.masterIp_.c_str();
  int         hostport = cfg_.masterPort_;

  serverNet.Connect(hostaddr, hostport);
  
  r3dOutToLog("connecting to master server at %s:%d\n", hostaddr, hostport);

  float endWait = r3dGetTime() + 10.0f;
  while(1) 
  {
    serverNet.Update();
  
    if(serverNet.IsConnected()) {
      break;
    }
      
    if(r3dGetTime() > endWait) {
      r3dError("can't connect to %s:%d", hostaddr, hostport);
      return 0;
    }
  }
  
  r3dOutToLog("Connect to master server Ok\n");

  started_ = true;
  return 1;
}
Example #2
0
bool CSupervisorServer::Start()
{
  SetConsoleTitle("WO::Supervisor");

  _mkdir("logsv");
  time_t t1;
  time(&t1);
  char fname[MAX_PATH];
  sprintf(fname, "logsv\\SV_%x.txt", (DWORD)t1);
  extern void r3dChangeLogFile(const char* fname);
  r3dChangeLogFile(fname);

  sprintf(fname, "logsv\\SV_%x.dmp", (DWORD)t1);
  SrvSetCrashHandler(fname);

  games_ = new CGameWatcher[gSupervisorConfig->maxGames_];

  serverNet.Initialize(this, "serverNet");
  serverNet.CreateClient();

  // try to connect for max 60sec, then exit.
  const float maxConnectTime = r3dGetTime() + 60.0f;
  while(1)
  {
    r3dStartFrame();
    r3dEndFrame();

    switch(ConnectToMasterServer())
    {
      default: 
        r3d_assert(0);
        break;
        
      case 1: // ok
        return true;
        
      case 2: // timeout
        r3dOutToLog("retrying in 2 sec\n");
        ::Sleep(2000);
        break;
      
      case 3: // disconnect
        r3dOutToLog("failed to connect to master server\n");
        return false;
    }
       
    if(r3dGetTime() > maxConnectTime) {
      r3dOutToLog("Timeout while connecting to master server\n");
      return false;
    }
  }
  
  r3d_assert(0);
}