Esempio n. 1
0
extern "C" void Disconnect(int worldId)
{
  SessionManager* pMgr = g_SessionManagers.Get(worldId);
  if (NULL != pMgr) {
    pMgr->SetSession(NULL);
  }
}
Esempio n. 2
0
static void ResetSessionManagers(void)
{
  const char* pCenterNum = GetConfig("centernum");
  int centerNum = 0;
  if (NULL != pCenterNum) {
    centerNum = (int)atoi(pCenterNum);
    for (int ix = 0; ix < centerNum; ++ix) {
      char temp[256];
      tsnprintf(temp, 256, "ip%d", ix);
      const char* pIp = GetConfig(temp);
      if (NULL == pIp)
        pIp = "127.0.0.1";
      tsnprintf(temp, 256, "port%d", ix);
      const char* pPort = GetConfig(temp);
      int port = 20000;
      if (NULL != pPort)
        port = (int)atoi(pPort);
      tsnprintf(temp, 256, "worldid%d", ix);
      const char* pWorldId = GetConfig(temp);
      int worldId = 0;
      if (NULL != pWorldId)
        worldId = (int)atoi(pWorldId);
      tsnprintf(temp, 256, "name%d", ix);
      const char* pName = GetConfig(temp);

      if (NULL != pWorldId && NULL != pName) {
        SessionManager* pMgr = g_SessionManagers.Get(worldId);
        if (NULL == pMgr) {
          pMgr = new SessionManager();
          pMgr->Init(g_EventBase);
          pMgr->SetIpPort(worldId, pIp, port);
          pMgr->UpdateMyName(pName);
          g_SessionManagers.Add(worldId, pMgr);
        } else {
          pMgr->SetIpPort(worldId, pIp, port);
          pMgr->UpdateMyName(pName);
          pMgr->SetSession(NULL);
        }
      }
    }
  }
}