Пример #1
0
/* reveive one packet from KRC (blocking!) */
int friUdp::Recv(tFriMsrData *packet)
{
    if (udpSock >= 0)
    {
        int received;
        struct timeval ts;
        
        received = RecvPacket(udpSock, packet, &ts, &krcAddr);

        if (received == sizeof(tFriMsrData))
        {
#ifdef HAVE_TIME_STAMP_RECEIVE

            /* FIXME: need another #ifdef for VxWorks */
#ifdef QNX
            struct timespec ts;
            clock_gettime(CLOCK_REALTIME, &ts);
            m_timestamp = (double)ts.tv_sec + (double)ts.tv_nsec/1.0e9;
#else
            m_timestamp = (double)ts.tv_sec + (double)ts.tv_usec/1.0e6;
#endif // QNX
#endif // HAVE_TIME_STAMP
            return 0;
        }
        else
        {
            printf("received something, but wrong size %d (expected %zu)...\n", received, sizeof(tFriMsrData));
            fflush(stdout);
        }
    }
    memset(packet, 0, sizeof(tFriMsrData));
    return -1;
}
Пример #2
0
void NetSocket::OnRecvData(const char* data, int dataLen)
{
    REFLIB_ASSERT_RETURN_IF_FAILED(data, "null data received.");
    REFLIB_ASSERT_RETURN_IF_FAILED(dataLen, "null size data received.");

    {
        SafeLock::Owner guard(_recvLock);
        REFLIB_ASSERT(_recvBuffer.PutData(data, dataLen), "Data loss: Not enough space");
    }

    MemoryBlock* buffer = nullptr;
    ePACKET_EXTRACT_RESULT ret = PER_NO_DATA;

    while ((ret = ExtractPakcetData(buffer)) == PER_SUCCESS)
    {
        if (!RecvPacket(buffer))
        {
            ret = PER_ERROR;
            break;
        }
    };

    if (ret == PER_ERROR)
        Disconnect(NET_CTYPE_SYSTEM);
}
void ReceiveAndRecoverSysCtrlNodeStates_(BackupSysCtrlNodeController* thiz, MySocket* sysCtrlNodeSocket) 
{
	Packet packet;
	char* stream;
	int length;
	printf("prepare to receive initialization data...\n");
	while (!RecvPacket(sysCtrlNodeSocket, &packet))
	{
		printf("receive initialization data failed, retrying...\n");
		Sleep(1000);
	}
	RecvStream(sysCtrlNodeSocket, &packet, &stream, &length);
	SysCtrlNodeRecoverStateFromStream(thiz->server_, stream, length);
	printf("initialization finished.\n");
	Free(stream);
}
Пример #4
0
// 使用串口协议接收数据
int CHvSerialLink::RecvCmdData(unsigned char* pbCmdId,
                               unsigned char* pbData,
                               unsigned int* pdwLen,
                               unsigned int dwRelayMs)
{
    static unsigned char s_recvData[MAX_PACK_LEN];

    unsigned int dwRecvLen = 0;

    if ( -1 == RecvPacket(s_recvData, &dwRecvLen, dwRelayMs))
    {
        return -1;
    }

    int hr = PickupDataFromPacket(s_recvData, dwRecvLen, pbCmdId, NULL, pbData,  pdwLen);
    if ( hr != 0 )
    {
        *pdwLen = 0;
    }
    return hr;
}
Пример #5
0
BOOL	DBThread::ProcessCacheCommand()
{
    PlayerID_t PlayerID ;

    _MY_TRY
    {
        BOOL ret = FALSE ;

        Packet* pPacket = NULL ;


        ret = RecvPacket( pPacket, PlayerID);


        if( !ret )
            return TRUE ;

        Player* pPlayer = g_pPlayerPool->GetPlayer( PlayerID ) ;
        if( pPlayer )
        {
            pPacket->Execute(pPlayer) ;
        }
        else
        {
            pPacket->Execute(NULL);
        }

        g_pPacketFactoryManager->RemovePacket( pPacket ) ;

        return TRUE;
    }

    _MY_CATCH
    {
        g_pLog->FastSaveLog(LOG_FILE_0,"DBThread::ProcessCacheCommand Get Errors,TID=%d,PlayerID =%d",getTID(),PlayerID);
        return TRUE;
    }


}
Пример #6
0
int Read(int fd, void (*dispatch)(GenericPacket*))
{
    GenericPacket* p;

    {
        int r = RecvPacket(fd, &p);

        if (r == -2)
            return 0;

        if (r != 0)
        {
            if (r > 0)
                printf("recv error: %d.\n", r);
            return 1;
        }
    }

    (*dispatch)(p);
    free(p);
    return 0;
}
Пример #7
0
int Dump(void)
{
	int exit = 0;
	int ret;
	uint16_t cmd, len;
	uint32_t addr;
	char str[30];
	unsigned int i;
	uint8_t* ptr;
	
	while(!exit)
	{
		// wait for command
		ret = RecvPacket(&cmd, &len, buf);
		//if(ret) continue;	// pb with ret val
		
		// or keypress
		if(kbhit()) 
			exit = !0;
					
		// and process
		switch(cmd)
		{
			case CMD_IS_READY: 
				Send_OK();
			break;
			case CMD_EXIT: 
				Send_EXIT();
				exit = !0; 
			break;
			case CMD_REQ_SIZE: 
				Send_SIZE(ROM_size);
				
				sprintf(str, "Size: %lu KB", ROM_size >> 10);
				DrawStr(0, 60, str, A_REPLACE	);
			break;
			case CMD_REQ_BLOCK: 
			  addr  = ((uint32_t)buf[0] <<  0); addr |= ((uint32_t)buf[1] <<  8);
			  addr |= ((uint32_t)buf[2] << 16); addr |= ((uint32_t)buf[3] << 24);
				
				if(addr > ROM_size)
					Send_ERR();

#if 0				
				if(addr >= 0x10000 && addr < 0x12000)	// read protected (certificate)
					addr = 0;	
				if(addr >= 0x18000 && addr < 0x1A000)	// read protected (certificate)
					addr = 0;
#endif
			
			  //sprintf(str, "%02x %02x %02x %02x     ", buf[0], buf[1], buf[2], buf[3]);
			  //DrawStr(0, 80, str, A_REPLACE	);
				sprintf(str, "Done: %lu/%luKB     ", addr >> 10, ROM_size >> 10);
				DrawStr(0, 60, str, A_REPLACE	);
				
				// Check for filled blocks (like 0xff)
				ptr = (uint8_t *)(ROM_base + addr);
				for(i = 0; i < BLK_SIZE; i++)
					if(ptr[i] != ptr[0])
						break;
				
				if(i == BLK_SIZE)
					Send_RDATA(ptr[0]);
				else
					Send_DATA(BLK_SIZE, (uint8_t *)(ROM_base + addr));
			break;
			case CMD_NONE:
			break;
			default:
			break;			
		}
	}	

	USBLinkClose();	
	return 0;
}
Пример #8
0
	bool			IAndroid::OnSocketMainUser(CMD_Command Command, void* pBuffer, WORD wDataSize)
	{
		switch(Command.wSubCmdID)
		{
		case SUB_GR_USER_COME:
			{
				if (wDataSize<sizeof(tagUserInfoHead)) 
					return 0;

				//读取基本信息
				tagUserInfoHead* pUserInfoHead = (tagUserInfoHead *)(pBuffer);

				SUser* pUser = m_pUserManager->Search(pUserInfoHead->dwUserID);
				if (!pUser)
					pUser = new SUser();

				if (pUser)
				{
					pUser->nScore		= pUserInfoHead->UserScoreInfo.lScore;	
					pUser->dwUserID		= pUserInfoHead->dwUserID;
					pUser->nScore		= pUserInfoHead->UserScoreInfo.lScore;
					pUser->wTableID		= pUserInfoHead->wTableID;
					pUser->wChairID		= pUserInfoHead->wChairID;
					pUser->cbUserStatus	= pUserInfoHead->cbUserStatus;
					pUser->dwGameID		= pUserInfoHead->dwGameID;

					// 设置登录时间
					time_t		timer	= time(NULL);
					struct tm * pTblock = localtime(&timer);
					sprintf(pUser->chLoginTime, "%s", asctime(pTblock));
					
					//读取扩展信息
					void* pDataBuffer		= NULL;
					tagDataDescribe DataDescribe;
					CRecvPacketHelper RecvPacket(pUserInfoHead+1, wDataSize-sizeof(tagUserInfoHead));
					while (true)
					{
						pDataBuffer=RecvPacket.GetData(DataDescribe);
						if (DataDescribe.wDataDescribe==DTP_NULL)
							break;

						switch (DataDescribe.wDataDescribe)
						{
						case DTP_USER_ACCOUNTS:		//用户帐户
							{
								if (DataDescribe.wDataSize<=sizeof(pUser->szName))
								{
									CopyMemory(&pUser->szName, pDataBuffer, DataDescribe.wDataSize);
									pUser->szName[CountArray(pUser->szName)-1] = 0;
								}
								break;
							}
						}
					}

					// 更新自己的状态信息
					if (pUser->dwUserID == m_dwUserID)
					{
						SetStatus(pUser->cbUserStatus);
					}

					// 添加到用户管理器
					m_pUserManager->Add(pUser);
				}
			}
			break;

		case SUB_GR_USER_STATUS:
			{
				if (wDataSize<sizeof(CMD_GR_UserStatus)) 
					return true;
				//处理数据
				CMD_GR_UserStatus* pUserStatus  = (CMD_GR_UserStatus *)pBuffer;
				SUser* pUser = m_pUserManager->Search(pUserStatus->dwUserID);
				if (pUser == NULL)
					return true;

				WORD wNowTableID	=	pUserStatus->wTableID;
				BYTE cbNowStatus	=	pUserStatus->cbUserStatus;
				WORD wNowChairID	=	pUserStatus->wChairID;

				WORD wLastTableID	=	pUser->wTableID;			
				BYTE cbLastStatus	=	pUser->cbUserStatus;
				WORD wLastChairID	=	pUser->wChairID;

				if (pUserStatus->cbUserStatus == US_NULL || pUserStatus->cbUserStatus == US_OFFLINE)
				{
					BankerManager::GetSingleton().Remove(pUser->dwUserID);
					// 移除该机器人
					m_pUserManager->Remove(pUserStatus->dwUserID);

					// 如果是自己
					if (pUserStatus->dwUserID == m_dwUserID)
					{
						SetStatus(US_OFFLINE);
					}
				}
				else
				{
					// 站起时响应存钱
					if (pUserStatus->cbUserStatus == US_FREE && pUserStatus->dwUserID == m_dwUserID)
					{
						BankerManager::GetSingleton().Remove(pUser->dwUserID);
						OnBanker();
						SetStatus(US_FREE);
					}
						
					//更新状态
					pUser->wTableID		= wNowTableID;
					pUser->wChairID		= wNowChairID;
					pUser->cbUserStatus = cbNowStatus;

					if (pUserStatus->cbUserStatus == US_SIT && pUserStatus->dwUserID == m_dwUserID 
						&& wNowTableID != INVALID_TABLE && ((wNowTableID!=wLastTableID) || (wNowChairID!=wLastChairID)))
					{
						// 设置为坐下状态
						SetStatus(US_SIT);

						m_wSitReqCount = 0;

						CString szMessage;
						szMessage.Format("[%d]已坐下", m_dwUserID);
						LogEvent(szMessage, 
							TraceLevel_Normal);	
					}
				}
			}
			break;

		case SUB_GR_USER_SCORE:
			{
				if (wDataSize<sizeof(CMD_GR_UserScore)) 
					return 0;

				//处理数据
				CMD_GR_UserScore* pUserScore = (CMD_GR_UserScore *)pBuffer;
				SUser* pGameUser = m_pUserManager->Search(pUserScore->dwUserID);
				if (pGameUser) 
				{
					pGameUser->nScore = pUserScore->UserScore.lScore;
				}
			}
			break;

		case SUB_GR_SIT_FAILED:
			{
				//消息处理
				CMD_GR_SitFailed* pSitFailed = (CMD_GR_SitFailed *)pBuffer;

				SAppConfig* pConfig = ConfigFile::GetSingleton().GetAppConfig();
				SUser* pGameUser = m_pUserManager->Search(m_dwUserID);
				if (pGameUser->nScore < pConfig->nMinScore) 
				{
					INT64 nMin = pConfig->nMinScore - pGameUser->nScore;
					INT64 nMax = pConfig->nMaxScore - pGameUser->nScore;
					GetScoreFromBanker(AndroidTimer::rdit(nMin, nMax));
				}
				CString szMessage;
				szMessage.Format("[%d] %s, 5秒后重连", m_dwUserID, pSitFailed->szFailedDescribe);
				LogEvent(szMessage, 
					TraceLevel_Normal);
			}
			break;
		}

		return true;
	}
Пример #9
0
void RenderDoc::RemoteAccessClientThread(void *s)
{
  Threading::KeepModuleAlive();

  Network::Socket *client = (Network::Socket *)s;

  Serialiser ser("", Serialiser::WRITING, false);

  string api = "";
  RDCDriver driver;
  RenderDoc::Inst().GetCurrentDriver(driver, api);

  ser.Rewind();

  string target = RenderDoc::Inst().GetCurrentTarget();
  ser.Serialise("", target);
  ser.Serialise("", api);
  uint32_t mypid = Process::GetCurrentPID();
  ser.Serialise("", mypid);

  if(!SendPacket(client, ePacket_Handshake, ser))
  {
    SAFE_DELETE(client);

    {
      SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
      RenderDoc::Inst().m_SingleClientName = "";
    }

    Threading::ReleaseModuleExitThread();
    return;
  }

  const int pingtime = 1000;    // ping every 1000ms
  const int ticktime = 10;      // tick every 10ms
  int curtime = 0;

  vector<CaptureData> captures;
  vector<pair<uint32_t, uint32_t> > children;

  while(client)
  {
    if(RenderDoc::Inst().m_RemoteClientThreadShutdown || (client && !client->Connected()))
    {
      SAFE_DELETE(client);
      break;
    }

    ser.Rewind();

    Threading::Sleep(ticktime);
    curtime += ticktime;

    PacketType packetType = ePacket_Noop;

    string curapi;
    RenderDoc::Inst().GetCurrentDriver(driver, curapi);

    vector<CaptureData> caps = RenderDoc::Inst().GetCaptures();
    vector<pair<uint32_t, uint32_t> > childprocs = RenderDoc::Inst().GetChildProcesses();

    if(curapi != api)
    {
      api = curapi;

      ser.Serialise("", api);

      packetType = ePacket_RegisterAPI;
    }
    else if(caps.size() != captures.size())
    {
      uint32_t idx = (uint32_t)captures.size();

      captures.push_back(caps[idx]);

      packetType = ePacket_NewCapture;

      std::string path = FileIO::GetFullPathname(captures.back().path);

      ser.Serialise("", idx);
      ser.Serialise("", captures.back().timestamp);
      ser.Serialise("", path);

      uint32_t len = 0;
      RENDERDOC_GetThumbnail(captures.back().path.c_str(), NULL, len);
      byte *thumb = new byte[len];
      RENDERDOC_GetThumbnail(captures.back().path.c_str(), thumb, len);

      size_t l = len;
      ser.Serialise("", len);
      ser.SerialiseBuffer("", thumb, l);
      delete[] thumb;
    }
    else if(childprocs.size() != children.size())
    {
      uint32_t idx = (uint32_t)children.size();

      children.push_back(childprocs[idx]);

      packetType = ePacket_NewChild;

      ser.Serialise("", children.back().first);
      ser.Serialise("", children.back().second);
    }

    if(curtime < pingtime && packetType == ePacket_Noop)
    {
      if(client->IsRecvDataWaiting())
      {
        PacketType type;
        Serialiser *recvser = NULL;

        if(!RecvPacket(client, type, &recvser))
          SAFE_DELETE(client);

        if(client == NULL)
        {
          SAFE_DELETE(recvser);
          continue;
        }
        else if(type == ePacket_TriggerCapture)
        {
          RenderDoc::Inst().TriggerCapture();
        }
        else if(type == ePacket_QueueCapture)
        {
          uint32_t frameNum = 0;
          recvser->Serialise("", frameNum);

          RenderDoc::Inst().QueueCapture(frameNum);
        }
        else if(type == ePacket_CopyCapture)
        {
          caps = RenderDoc::Inst().GetCaptures();

          uint32_t id = 0;
          recvser->Serialise("", id);

          if(id < caps.size())
          {
            ser.Serialise("", id);

            if(!SendPacket(client, ePacket_CopyCapture, ser))
            {
              SAFE_DELETE(client);
              continue;
            }

            ser.Rewind();

            if(!SendChunkedFile(client, ePacket_CopyCapture, caps[id].path.c_str(), ser, NULL))
            {
              SAFE_DELETE(client);
              continue;
            }

            RenderDoc::Inst().MarkCaptureRetrieved(id);
          }
        }

        SAFE_DELETE(recvser);
      }

      continue;
    }

    curtime = 0;

    if(!SendPacket(client, packetType, ser))
    {
      SAFE_DELETE(client);
      continue;
    }
  }

  // give up our connection
  {
    SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
    RenderDoc::Inst().m_SingleClientName = "";
  }

  Threading::ReleaseModuleExitThread();
}
Пример #10
0
 void GetPacket(PacketType &type, Serialiser *&ser)
 {
   if(!RecvPacket(m_Socket, type, &ser))
     SAFE_DELETE(m_Socket);
 }
// run when other server down and reconnect in
void BackupSysCtrlNodeReceivingThreadMain(void* handlingHelperParameter)
{
	SocketHandlerParameter* parameter;
	BackupSysCtrlNodeController* thiz;
	MySocket* sysCtrlNodeSocket;
	Packet packet;

	int dummy;


	parameter = ((SocketHandlerParameter*) handlingHelperParameter);
	thiz = (BackupSysCtrlNodeController*) parameter->connector;
	sysCtrlNodeSocket = parameter->socket;


	printf("a BackupSysCtrlNode receiving thread start.\n");
	while (thiz->isRunning_)
	{
		bool success;
		success = RecvPacket(sysCtrlNodeSocket, &packet);
		if (!success && thiz->isRunning_)
		{

// 			BackupSysCtrlNodeControllerStartBackupSysCtrlNode_(thiz);
// 			BackupSysCtrlNodeControllerReconnect_(thiz, sendingSocket);
			// sending thread will do this
			break;

		}

		if (!thiz->isRunning_)
		{
			break;
		}


		switch(packet.head.iStyle)
		{
		case PROTOCOL_LOGIN:
			{
				dummy = SysCtrlNodeGetPayloadNodeCount(thiz->server_) != 0;
				assert(dummy);
				if (g_configData.bLogAllMsg)
				{
					printf("SysCtrlNode send a sync message PROTOCOL_LOGIN, userID: %d\n", packet.head.iID);
				}
				success = SysCtrlNodeConnectRequest(thiz->server_, packet.head.iID, &dummy);
			}
			break;
		case PROTOCOL_LOGOUT:
			{
				dummy = SysCtrlNodeGetPayloadNodeCount(thiz->server_) != 0;
				assert(dummy);
				if (g_configData.bLogAllMsg)
				{
					printf("SysCtrlNode send a sync message PROTOCOL_LOGOUT, userID: %d\n", packet.head.iID);
				}
				success = SysCtrlNodeReleaseRequest(thiz->server_, packet.head.iID, &dummy);
			}
			break;
		case PROTOCOL_CLEAR_PAYLOAD:
			{
				if (g_configData.bLogAllMsg)
				{
					printf("SysCtrlNode send a sycn message PROTOCOL_CLEAR_PAYLOAD\n");
				}
				dummy = SysCtrlNodeClearAllPayLoads(thiz->server_);
			}
			break;
		case PROTOCOL_SHUTDOWN_SYSTEM:
			{
				thiz->isRunning_ = false;
				SysCtrlNodeShutdownSystem(thiz->server_);
			}
			break;
		case PROTOCOL_QUERY_INFO_ACK:
			{
				assert(false);
			}
			break;
		case PROTOCOL_SYSCTRLNODE_SET_INACTIVE:
			{
				SysCtrlNodeSetToInactiveServer(thiz->server_);
			}
			break;
		default:
			{
				printf("error: receive an illegal message in BackupSysCtrlNode receiving thread.\n");
				break;
			}
		}
	}
	BackupSysCtrlNodeControllerDisconnectReceivingSocket_(thiz, thiz->receivingHandler_);
	thiz->receivingHandler_ = NULL;
}
Пример #12
0
void RenderDoc::RemoteAccessServerThread(void *s)
{
  Threading::KeepModuleAlive();

  Network::Socket *sock = (Network::Socket *)s;

  RenderDoc::Inst().m_SingleClientName = "";

  Threading::ThreadHandle clientThread = 0;

  RenderDoc::Inst().m_RemoteClientThreadShutdown = false;

  while(!RenderDoc::Inst().m_RemoteServerThreadShutdown)
  {
    Network::Socket *client = sock->AcceptClient(false);

    if(client == NULL)
    {
      if(!sock->Connected())
      {
        RDCERR("Error in accept - shutting down server");

        SAFE_DELETE(sock);
        Threading::ReleaseModuleExitThread();
        return;
      }

      Threading::Sleep(5);

      continue;
    }

    string existingClient;
    string newClient;
    bool kick = false;

    // receive handshake from client and get its name
    {
      PacketType type;
      Serialiser *ser = NULL;
      if(!RecvPacket(client, type, &ser))
      {
        SAFE_DELETE(ser);
        SAFE_DELETE(client);
        continue;
      }

      if(type != ePacket_Handshake)
      {
        SAFE_DELETE(ser);
        SAFE_DELETE(client);
        continue;
      }

      ser->SerialiseString("", newClient);
      ser->Serialise("", kick);

      SAFE_DELETE(ser);

      if(newClient.empty())
      {
        SAFE_DELETE(client);
        continue;
      }
    }

    // see if we have a client
    {
      SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
      existingClient = RenderDoc::Inst().m_SingleClientName;
    }

    if(!existingClient.empty() && kick)
    {
      // forcibly close communication thread which will kill the connection
      RenderDoc::Inst().m_RemoteClientThreadShutdown = true;
      Threading::JoinThread(clientThread);
      Threading::CloseThread(clientThread);
      clientThread = 0;
      RenderDoc::Inst().m_RemoteClientThreadShutdown = false;
      existingClient = "";
    }

    if(existingClient.empty())
    {
      SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
      RenderDoc::Inst().m_SingleClientName = newClient;
    }

    // if we've claimed client status, spawn a thread to communicate
    if(existingClient.empty() || kick)
    {
      clientThread = Threading::CreateThread(RemoteAccessClientThread, client);
      continue;
    }
    else
    {
      // if we've been asked to kick the existing connection off
      // reject this connection and tell them who is busy
      Serialiser ser("", Serialiser::WRITING, false);

      string api = "";
      RDCDriver driver;
      RenderDoc::Inst().GetCurrentDriver(driver, api);

      string target = RenderDoc::Inst().GetCurrentTarget();
      ser.Serialise("", target);
      ser.Serialise("", api);

      ser.SerialiseString("", RenderDoc::Inst().m_SingleClientName);

      // don't care about errors, we're going to close the connection either way
      SendPacket(client, ePacket_Busy, ser);

      SAFE_DELETE(client);
    }
  }

  RenderDoc::Inst().m_RemoteClientThreadShutdown = true;
  // don't join, just close the thread, as we can't wait while in the middle of module unloading
  Threading::CloseThread(clientThread);
  clientThread = 0;

  Threading::ReleaseModuleExitThread();
}
// only run once
void BackupSysCtrlNodeSendingThreadMain(void* handlingHelperParameter)
{
	SocketHandlerParameter* parameter;
	BackupSysCtrlNodeController* thiz;
	MySocket* sendingSocket;
	Packet packet;
	bool success;

	printf("a BackupSysCtrlNode sending thread start.\n");

	parameter = ((SocketHandlerParameter*) handlingHelperParameter);
	thiz = (BackupSysCtrlNodeController*) parameter->connector;
	//sendingSocket = parameter->socket; // parameter->socket is NULL


	sendingSocket = TypedMalloc(MySocket);
	success = Create(sendingSocket);
	assert(success);
	success = success && Connect(sendingSocket, thiz->ip_, thiz->portToConnect_);
	if (!success)
	{
		while(!ConnectWithTimeout(sendingSocket, thiz->ip_, thiz->portToListen_, 1))
		{
		}
		success = true;
	}
	parameter->socket = sendingSocket;

	printf("connection to other SysCtrlNode established.\n");

	if (thiz->server_->isBackupServer_)
	{
		printf("sync sys ctrl node states...\n");
		ReceiveAndRecoverSysCtrlNodeStates_(thiz, sendingSocket);
		printf("finish sync sys ctrl node states.\n");
		SetEvent(thiz->waitingForInitializationData_);
	}

	while (thiz->isRunning_)
	{

		success = RecvPacket(sendingSocket, &packet);
		if (!success && thiz->isRunning_)
		{
			printf("another server closed.\n");
			SysCtrlNodeSetToActiveServer(thiz->server_);
			BackupSysCtrlNodeControllerStartBackupSysCtrlNode_(thiz);
			BackupSysCtrlNodeControllerReconnect_(thiz, sendingSocket);

			continue;

		}

		if (!thiz->isRunning_)
		{
			break;
		}

		// actually, sending thread will never receive a message
		switch(packet.head.iStyle)
		{
		case PROTOCOL_SHUTDOWN_SYSTEM:
			{
				assert(false);
			}
			break;
		default:
			{
				printf("error: receive an illegal message in BackupSysCtrlNode sending thread.\n");
				break;
			}
		}
	}
	thiz->sendingHandler_ = NULL;
	printf("BackupSysCtrlNode connector shutdown.\n");
}
Пример #14
0
void RenderDoc::RemoteAccessClientThread(void *s)
{
	Network::Socket *client = (Network::Socket *)s;

	Serialiser ser(L"", Serialiser::WRITING, false);

	wstring api = L"";
	RDCDriver driver;
	RenderDoc::Inst().GetCurrentDriver(driver, api);

	ser.Rewind();

	wstring target = RenderDoc::Inst().GetCurrentTarget();
	ser.Serialise("", target);
	ser.Serialise("", api);

	if(!SendPacket(client, ePacket_Handshake, ser))
	{
		SAFE_DELETE(client);

		{
			SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
			RenderDoc::Inst().m_SingleClientName = L"";
		}

		return;
	}

	const int pingtime = 1000; // ping every 1000ms
	const int ticktime = 10; // tick every 10ms
	int curtime = 0;

	vector<wstring> captures;

	while(client)
	{
		if(RenderDoc::Inst().m_RemoteClientThreadShutdown || (client && !client->Connected()))
		{
			SAFE_DELETE(client);
			break;
		}

		ser.Rewind();

		Threading::Sleep(ticktime);
		curtime += ticktime;

		PacketType packetType = ePacket_Noop;

		wstring curapi;
		RenderDoc::Inst().GetCurrentDriver(driver, curapi);

		if(curapi != api)
		{
			api = curapi;

			ser.Serialise("", api);

			packetType = ePacket_RegisterAPI;
		}
		else
		{
			vector<wstring> caps = RenderDoc::Inst().GetCaptures();

			if(caps.size() != captures.size())
			{
				uint32_t idx = (uint32_t)captures.size();

				captures.push_back(caps[idx]);

				packetType = ePacket_NewCapture;

				uint64_t timestamp = FileIO::GetModifiedTimestamp(captures.back().c_str());
				ser.Serialise("", idx);
				ser.Serialise("", timestamp);

				ser.Serialise("", captures.back());

				uint32_t len = 128*1024;
				byte *thumb = new byte[len];
				RENDERDOC_GetThumbnail(captures.back().c_str(), thumb, len);

				size_t l = len;
				ser.Serialise("", len);
				ser.SerialiseBuffer("", thumb, l);
				delete[] thumb;
			}
		}

		if(curtime < pingtime && packetType == ePacket_Noop)
		{
			if(client->IsRecvDataWaiting())
			{
				PacketType type;
				Serialiser *recvser = NULL;

				if(!RecvPacket(client, type, &recvser))
					SAFE_DELETE(client);

				if(client == NULL)
				{
					SAFE_DELETE(recvser);
					continue;
				}
				else if(type == ePacket_TriggerCapture)
				{
					RenderDoc::Inst().TriggerCapture();
				}
				else if(type == ePacket_QueueCapture)
				{
					uint32_t frameNum = 0;
					recvser->Serialise("", frameNum);
					
					RenderDoc::Inst().QueueCapture(frameNum);
				}
				else if(type == ePacket_CopyCapture)
				{
					vector<wstring> caps = RenderDoc::Inst().GetCaptures();

					uint32_t id = 0;
					recvser->Serialise("", id);

					if(id < caps.size())
					{
						ser.Serialise("", id);

						if(!SendPacket(client, ePacket_CopyCapture, ser))
						{
							SAFE_DELETE(client);
							continue;
						}

						ser.Rewind();

						if(!SendChunkedFile(client, ePacket_CopyCapture, caps[id].c_str(), ser, NULL))
						{
							SAFE_DELETE(client);
							continue;
						}

						RenderDoc::Inst().MarkCaptureRetrieved(id);
					}
				}

				SAFE_DELETE(recvser);
			}

			continue;
		}

		curtime = 0;

		if(!SendPacket(client, packetType, ser))
		{
			SAFE_DELETE(client);
			continue;
		}
	}
	
	// give up our connection
	{
		SCOPED_LOCK(RenderDoc::Inst().m_SingleClientLock);
		RenderDoc::Inst().m_SingleClientName = L"";
	}
}
Пример #15
0
//---------------------------------------------------------------------------
int TIsoTcpSocket::isoConnect()
{
	pbyte TmpControlPDU;
    PIsoControlPDU ControlPDU;
	u_int Length;
	int Result;

	// Build the default connection telegram
	BuildControlPDU();
    ControlPDU =&FControlPDU;

	// Checks the format
	Result =CheckPDU(ControlPDU, pdu_type_CR);
	if (Result!=0)
		return Result;

	Result =SckConnect();
	if (Result==noError)
	{
		// Calcs the length
		Length =PDUSize(ControlPDU);
		// Send connection telegram
		SendPacket(ControlPDU, Length);
		if (LastTcpError==0)
		{
			TmpControlPDU = pbyte(ControlPDU);
			// Receives TPKT header (4 bytes)
			RecvPacket(TmpControlPDU, sizeof(TTPKT));
			if (LastTcpError==0)
			{
				// Calc the packet length
				Length =PDUSize(TmpControlPDU);
				// Check if it fits in the buffer and if it's greater then TTPKT size
				if ((Length<=sizeof(TIsoControlPDU)) && (Length>sizeof(TTPKT)))
				{
					// Points to COTP
					TmpControlPDU+=sizeof(TTPKT);
					Length -= sizeof(TTPKT);
					// Receives remainin bytes 4 bytes after
					RecvPacket(TmpControlPDU, Length);
					if (LastTcpError==0)
					{
						// Finally checks the Connection Confirm telegram
						Result =CheckPDU(ControlPDU, pdu_type_CC);
						if (Result!=0)
							LastIsoError=Result;
					}
					else
						Result =SetIsoError(errIsoRecvPacket);
				}
				else
					Result =SetIsoError(errIsoInvalidPDU);
			}
			else
				Result =SetIsoError(errIsoRecvPacket);
			// Flush buffer
			if (Result!=0)
				Purge();
		}
		else
			Result =SetIsoError(errIsoSendPacket);

		if (Result!=0)
			SckDisconnect();
	}
	return Result;
}
Пример #16
0
//用户通知
bool CClientKernel::OnIPCUser(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend)
{
	ASSERT(pHead->wMainCmdID==IPC_MAIN_USER);
	switch (pHead->wSubCmdID)
	{
	case IPC_SUB_USER_COME:		//用户消息
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(tagUserInfoHead));
			if (wDataSize<sizeof(tagUserInfoHead)) return false;

			//读取基本信息
			tagUserData UserData;
			memset(&UserData,0,sizeof(UserData));
			tagUserInfoHead * pUserInfoHead=(tagUserInfoHead *)pIPCBuffer;
			UserData.wFaceID=pUserInfoHead->wFaceID;
			UserData.wTableID=pUserInfoHead->wTableID;
			UserData.wChairID=pUserInfoHead->wChairID;
			UserData.cbGender=pUserInfoHead->cbGender;
			UserData.cbUserStatus=pUserInfoHead->cbUserStatus;
			UserData.cbMemberOrder=pUserInfoHead->cbMemberOrder;
			UserData.cbMasterOrder=pUserInfoHead->cbMasterOrder;
			UserData.dwUserID=pUserInfoHead->dwUserID;
			UserData.dwGameID=pUserInfoHead->dwGameID;
			UserData.dwGroupID=pUserInfoHead->dwGroupID;
			UserData.dwUserRight=pUserInfoHead->dwUserRight;
			UserData.dwMasterRight=pUserInfoHead->dwMasterRight;
			UserData.lScore=pUserInfoHead->UserScoreInfo.lScore;
			UserData.lWinCount=pUserInfoHead->UserScoreInfo.lWinCount;
			UserData.lLostCount=pUserInfoHead->UserScoreInfo.lLostCount;
			UserData.lDrawCount=pUserInfoHead->UserScoreInfo.lDrawCount;
			UserData.lFleeCount=pUserInfoHead->UserScoreInfo.lFleeCount;
			UserData.lExperience=pUserInfoHead->UserScoreInfo.lExperience;

			//读取扩展信息
			void * pDataBuffer=NULL;
			tagDataDescribe DataDescribe;
			CRecvPacketHelper RecvPacket(pUserInfoHead+1,wDataSize-sizeof(tagUserInfoHead));
			while (true)
			{
				pDataBuffer=RecvPacket.GetData(DataDescribe);
				if (DataDescribe.wDataDescribe==DTP_NULL) break;
				switch (DataDescribe.wDataDescribe)
				{
				case DTP_USER_ACCOUNTS:		//用户帐户
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szName));
						if (DataDescribe.wDataSize<=sizeof(UserData.szName))
						{
							CopyMemory(&UserData.szName,pDataBuffer,DataDescribe.wDataSize);
							UserData.szName[CountArray(UserData.szName)-1]=0;
						}
						break;
					}
				case DTP_UNDER_WRITE:		//个性签名
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite));
						if (DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite))
						{
							CopyMemory(&UserData.szUnderWrite,pDataBuffer,DataDescribe.wDataSize);
							UserData.szUnderWrite[CountArray(UserData.szUnderWrite)-1]=0;
						}
						break;
					}
				case DTP_USER_GROUP_NAME:	//用户社团
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szGroupName));
						if (DataDescribe.wDataSize<=sizeof(UserData.szGroupName))
						{
							CopyMemory(&UserData.szGroupName,pDataBuffer,DataDescribe.wDataSize);
							UserData.szGroupName[CountArray(UserData.szGroupName)-1]=0;
						}
						break;
					}
				case DTP_USER_COMPANION:	//用户关系
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.cbCompanion));
						if (DataDescribe.wDataSize<=sizeof(UserData.cbCompanion))
						{
							CopyMemory(&UserData.cbCompanion,pDataBuffer,DataDescribe.wDataSize);
						}
						break;
					}
				}
			}

			//增加用户
			ActiveUserItem(&UserData);

			return true;
		}
	case IPC_SUB_USER_STATUS:	//用户状态
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(IPC_UserStatus));
			if (wDataSize<sizeof(IPC_UserStatus)) return false;

			//消息处理
			IPC_UserStatus * pUserStatus=(IPC_UserStatus *)pIPCBuffer;
			if (pUserStatus->cbUserStatus<US_SIT) 
			{
				if (pUserStatus->dwUserID==m_dwUserID)
				{
					ResetClientKernel();
					return true;
				}
				else DeleteUserItem(pUserStatus->dwUserID);
			}
			else UpdateUserItem(pUserStatus->dwUserID,pUserStatus->cbUserStatus,pUserStatus->wNetDelay);

			return true;
		}
	case IPC_SUB_USER_SCORE:	//用户积分
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(IPC_UserScore));
			if (wDataSize<sizeof(IPC_UserScore)) return false;

			//消息处理
			IPC_UserScore * pUserScore=(IPC_UserScore *)pIPCBuffer;
			UpdateUserItem(pUserScore->dwUserID,&pUserScore->UserScore);

			return true;
		}
	case IPC_SUB_GAME_START:	//游戏开始
		{
			//设置用户
			for (WORD i=0;i<m_ServerAttribute.wChairCount;i++)
			{
				if (m_pUserItem[i]!=NULL) 
				{
					m_pUserItem[i]->cbUserStatus=US_PLAY;
					m_pIClientKernelSink->OnEventUserStatus(m_pUserItem[i],m_pUserItem[i]->wChairID,false);
				}
			}

			return true;
		}
	case IPC_SUB_GAME_FINISH:	//游戏结束
		{
			//设置用户
			for (WORD i=0;i<m_ServerAttribute.wChairCount;i++)
			{
				if (m_pUserItem[i]!=NULL)
				{
					m_pUserItem[i]->cbUserStatus=US_SIT;
					m_pIClientKernelSink->OnEventUserStatus(m_pUserItem[i],m_pUserItem[i]->wChairID,false);
				}
			}

			return true;
		}
	}

	return false;
}
Пример #17
0
//登录消息
bool CPlazaViewItem::OnSocketMainLogon(CMD_Command Command, void * pData, WORD wDataSize)
{
	switch (Command.wSubCmdID)
	{
	case SUB_GP_LOGON_SUCCESS:		//登录成功
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(CMD_GP_LogonSuccess));
			if (wDataSize<sizeof(CMD_GP_LogonSuccess)) return false;

			//保存信息
			tagGlobalUserData & UserData=g_GlobalUnits.GetGolbalUserData();
			CMD_GP_LogonSuccess * pLogonSuccess=(CMD_GP_LogonSuccess *)pData;
			UserData.wFaceID=pLogonSuccess->wFaceID;
			UserData.cbGender=pLogonSuccess->cbGender;
			UserData.cbMember=pLogonSuccess->cbMember;
			UserData.dwUserID=pLogonSuccess->dwUserID;
			UserData.dwGameID=pLogonSuccess->dwGameID;
			UserData.dwExperience=pLogonSuccess->dwExperience;
			UserData.dwCustomFaceVer=pLogonSuccess->dwCustomFaceVer;

			//扩展信息
			void * pDataBuffer=NULL;
			tagDataDescribe DataDescribe;
			CRecvPacketHelper RecvPacket(pLogonSuccess+1,wDataSize-sizeof(CMD_GP_LogonSuccess));
			while (true)
			{
				pDataBuffer=RecvPacket.GetData(DataDescribe);
				if (DataDescribe.wDataDescribe==DTP_NULL) break;
				switch (DataDescribe.wDataDescribe)
				{
				case DTP_USER_ACCOUNTS:		//用户帐户
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szAccounts));
						if (DataDescribe.wDataSize<=sizeof(UserData.szAccounts))
						{
							CopyMemory(UserData.szAccounts,pDataBuffer,DataDescribe.wDataSize);
							UserData.szAccounts[CountArray(UserData.szAccounts)-1]=0;
						}
						break;
					}
				case DTP_USER_PASS:			//用户密码
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szPassWord));
						if (DataDescribe.wDataSize<=sizeof(UserData.szPassWord))
						{
							CopyMemory(UserData.szPassWord,pDataBuffer,DataDescribe.wDataSize);
							UserData.szPassWord[CountArray(UserData.szPassWord)-1]=0;
						}
						break;
					}
				case DTP_UNDER_WRITE:		//个性签名
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite));
						if (DataDescribe.wDataSize<=sizeof(UserData.szUnderWrite))
						{
							CopyMemory(UserData.szUnderWrite,pDataBuffer,DataDescribe.wDataSize);
							UserData.szUnderWrite[CountArray(UserData.szUnderWrite)-1]=0;
						}
						break;
					}
				case DTP_USER_GROUP_NAME:	//社团名字
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szGroupName));
						if (DataDescribe.wDataSize<=sizeof(UserData.szGroupName))
						{
							CopyMemory(UserData.szGroupName,pDataBuffer,DataDescribe.wDataSize);
							UserData.szGroupName[CountArray(UserData.szGroupName)-1]=0;
						}
						break;
					}
				case DTP_STATION_PAGE:		//游戏主站
					{
						ASSERT(pDataBuffer!=NULL);
						if (pDataBuffer!=NULL) 
						{
							g_GlobalUnits.SetStationPage((LPCTSTR)pDataBuffer);
							m_pHtmlBrower->Navigate(g_GlobalUnits.GetStationPage());
						}
						break;
					}
				default: { ASSERT(FALSE); }
				}
			}

			//设置提示
			g_GlobalAttemper.ShowStatusMessage(TEXT("正在读取服务器列表信息..."),this);

			return true;
		}
	case SUB_GP_LOGON_ERROR:		//登录失败
		{
			//效验参数
			CMD_GP_LogonError *pLogonError = (CMD_GP_LogonError *)pData;
			ASSERT(wDataSize>=(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe)));
			if (wDataSize<(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe))) return false;

			//关闭连接
			g_GlobalAttemper.DestroyStatusWnd(this);
			m_ClientSocket->CloseSocket();

			//显示消息
			WORD wDescribeSize=wDataSize-(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe));
			if (wDescribeSize>0)
			{
				pLogonError->szErrorDescribe[wDescribeSize-1]=0;
				ShowMessageBox(pLogonError->szErrorDescribe,MB_ICONINFORMATION);
			}

			//发送登录
			SendLogonMessage();

			return true;
		}
	case SUB_GP_LOGON_FINISH:		//登录完成
		{
			//关闭提示
			g_GlobalAttemper.DestroyStatusWnd(this);

			//展开类型
			INT_PTR nIndex=0;
			CListType * pListType=NULL;
			do
			{
				pListType=g_GlobalUnits.m_ServerListManager.EnumTypeItem(nIndex++);
				if (pListType==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListType);
			} while (true);

			//展开列表
			nIndex=0;
			CListInside * pListInside=NULL;
			do
			{
				pListInside=g_GlobalUnits.m_ServerListManager.EnumInsideItem(nIndex++);
				if (pListInside==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListInside);
			} while (true);

			//记录信息
			m_bLogonPlaza=true;
			m_DlgLogon.OnLogonSuccess();
			m_pHtmlBrower->EnableBrowser(true);

			//记录信息
			g_GlobalUnits.WriteUserCookie();

			//显示头像
			((CGameFrame*)AfxGetMainWnd())->m_UserInfoView.ShowUserInfo(true);

			//自定义判断
			tagGlobalUserData &GlobalUserData = g_GlobalUnits.GetGolbalUserData();
			if ( GlobalUserData.dwCustomFaceVer!=0)
			{
				//头像名称
				CString strDirName = CString(g_GlobalUnits.GetWorkDirectory()) + TEXT("\\CustomFace");
				CString strFileName;
				strFileName.Format(TEXT("\\%ld_%d.bmp"), GlobalUserData.dwUserID, GlobalUserData.dwCustomFaceVer);

				//读取文件
				CImage FaceImage;
				HRESULT hResult = FaceImage.Load(strDirName + strFileName);
				if (SUCCEEDED(hResult))
				{
					//关闭连接
					m_ClientSocket->CloseSocket();

					FaceImage.Destroy();
				}
				//下载头像
				else
				{
					PostMessage(WM_DOWN_LOAD_FACE, LPARAM(GlobalUserData.dwCustomFaceVer), WPARAM(GlobalUserData.dwUserID));
				}
			}
			else
			{
				//关闭连接
				m_ClientSocket->CloseSocket();
			}

			return true;
		}
	}

	return true;
}
Пример #18
0
//登陆消息
bool CPlazaViewItem::OnSocketMainLogon(CMD_Command Command, 
									   void *pBuffer, 
									   WORD wDataSize, 
									   IClientSocket *pIClientSocke)
{
	ASSERT(Command.wMainCmdID==MDM_GP_LOGON);
	switch (Command.wSubCmdID)
	{
		//登陆成功
	case SUB_GP_LOGON_SUCCESS:		
		{
			//效验参数
			ASSERT(wDataSize>=sizeof(CMD_GP_LogonSuccess));
			if (wDataSize<sizeof(CMD_GP_LogonSuccess)) 
			{
				return false;
			}

			//保存信息
			tagGlobalUserData & UserData=g_GlobalUnits.GetGolbalUserData();
			CMD_GP_LogonSuccess * pLogonSuccess=(CMD_GP_LogonSuccess *)pBuffer;
			UserData.wFaceID=pLogonSuccess->wFaceID;
			UserData.cbGender=pLogonSuccess->cbGender;
			UserData.cbMember=pLogonSuccess->cbMember;
			UserData.dwUserID=pLogonSuccess->dwUserID;
			UserData.dwGroupID=pLogonSuccess->dwGroupID;
			UserData.dwExperience=pLogonSuccess->dwExperience;
			UserData.dwUserRight=pLogonSuccess->dwUserRight;
			UserData.dwMasterRight=pLogonSuccess->dwMasterRight;

			//扩展信息
			void * pDataBuffer=NULL;
			tagDataDescribe DataDescribe;
			CRecvPacketHelper RecvPacket(pLogonSuccess+1,wDataSize-sizeof(CMD_GP_LogonSuccess));
			while (true)
			{
				pDataBuffer=RecvPacket.GetData(DataDescribe);
				if (DataDescribe.wDataDescribe==DTP_NULL) break;
				switch (DataDescribe.wDataDescribe)
				{
				case DTP_USER_ACCOUNTS:		//用户帐户
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szAccounts));
						if (DataDescribe.wDataSize<=sizeof(UserData.szAccounts))
						{
							CopyMemory(UserData.szAccounts,pDataBuffer,DataDescribe.wDataSize);
							UserData.szAccounts[CountArray(UserData.szAccounts)-1]=0;
						}
						break;
					}
				case DTP_USER_PASS:			//用户密码
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szPassWord));
						if (DataDescribe.wDataSize<=sizeof(UserData.szPassWord))
						{
							CopyMemory(UserData.szPassWord,pDataBuffer,DataDescribe.wDataSize);
							UserData.szPassWord[CountArray(UserData.szPassWord)-1]=0;
						}
						break;
					}
				case DTP_USER_GROUP_NAME:	//社团名字
					{
						ASSERT(pDataBuffer!=NULL);
						ASSERT(DataDescribe.wDataSize>0);
						ASSERT(DataDescribe.wDataSize<=sizeof(UserData.szGroupName));
						if (DataDescribe.wDataSize<=sizeof(UserData.szGroupName))
						{
							CopyMemory(UserData.szGroupName,pDataBuffer,DataDescribe.wDataSize);
							UserData.szGroupName[CountArray(UserData.szGroupName)-1]=0;
						}
						break;
					}
				case DTP_STATION_PAGE:		//游戏主站
					{
						ASSERT(pDataBuffer!=NULL);
						if (pDataBuffer!=NULL) 
						{
							g_GlobalUnits.SetStationPage((LPCTSTR)pDataBuffer);
							m_pHtmlBrower->Navigate(g_GlobalUnits.GetStationPage());
						}
						break;
					}
				default: { ASSERT(FALSE); }
				}
			}

			//刷新界面
			Invalidate(TRUE);

			//设置提示
			g_GlobalAttemper.ShowStatusMessage(TEXT("正在读取服务器列表信息..."),this);

			return true;
		}

		//登陆失败
	case SUB_GP_LOGON_ERROR:		
		{
			//效验参数
			CMD_GP_LogonError *pLogonError = (CMD_GP_LogonError *)pBuffer;
			ASSERT(wDataSize>=(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe)));
			if (wDataSize<(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe))) return false;

			//关闭连接
			g_GlobalAttemper.DestroyStatusWnd(this);
			pIClientSocke->CloseSocket(false);

			//显示消息
			WORD wDescribeSize=wDataSize-(sizeof(CMD_GP_LogonError)-sizeof(pLogonError->szErrorDescribe));
			if (wDescribeSize>0)
			{
				pLogonError->szErrorDescribe[wDescribeSize-1]=0;
				ShowMessageBox(pLogonError->szErrorDescribe,MB_ICONINFORMATION);
			}

			//发送登陆
			SendLogonMessage();

			return true;
		}

		//登陆完成
	case SUB_GP_LOGON_FINISH:		
		{
			//关闭提示
			g_GlobalAttemper.DestroyStatusWnd(this);

			//展开类型
			INT_PTR nIndex=0;
			CListType * pListType=NULL;
			do
			{
				pListType=g_GlobalUnits.m_ServerListManager.EnumTypeItem(nIndex++);
				if (pListType==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListType);
			} while (true);

			//展开列表
			nIndex=0;
			CListInside * pListInside=NULL;
			do
			{
				pListInside=g_GlobalUnits.m_ServerListManager.EnumInsideItem(nIndex++);
				if (pListInside==NULL) break;
				g_GlobalUnits.m_ServerListManager.ExpandListItem(pListInside);
			} while (true);

			//记录信息
			m_bLogonPlaza=true;
			m_DlgLogon.OnLogonSuccess();
			m_pHtmlBrower->EnableBrowser(true);

			return true;
		}
	}

	return true;
}
Пример #19
0
//用户通知
bool CClientKernel::OnIPCUser(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend)
{
    switch (pHead->wSubCmdID)
    {
    case IPC_SUB_USER_COME:		//用户消息
        {
            //效验参数
            if (wDataSize<sizeof(tagUserInfoHead)) return false;


            //读取基本信息
            tagUserData *pUserData = new tagUserData;

            tagUserInfoHead * pUserInfoHead=(tagUserInfoHead *)pIPCBuffer;

            pUserData->wFaceID=pUserInfoHead->wFaceID;
            //pUserData->dwCustomFaceVer=pUserInfoHead->dwCustomFaceVer;
            pUserData->wTableID=pUserInfoHead->wTableID;
            pUserData->wChairID=pUserInfoHead->wChairID;
            pUserData->cbGender=pUserInfoHead->cbGender;
            pUserData->cbUserStatus=pUserInfoHead->cbUserStatus;
            pUserData->cbMemberOrder=pUserInfoHead->cbMemberOrder;
            pUserData->cbMasterOrder=pUserInfoHead->cbMasterOrder;
            pUserData->dwUserID=pUserInfoHead->dwUserID;
            pUserData->dwGameID=pUserInfoHead->dwGameID;
            pUserData->dwGroupID=pUserInfoHead->dwGroupID;
            pUserData->dwUserRight=pUserInfoHead->dwUserRight;
            //pUserData->dwLoveliness=pUserInfoHead->dwLoveliness;
            pUserData->dwMasterRight=pUserInfoHead->dwMasterRight;
            pUserData->lScore=pUserInfoHead->UserScoreInfo.lScore;
            //pUserData->lGameGold=pUserInfoHead->UserScoreInfo.lGameGold;
            //pUserData->lInsureScore=pUserInfoHead->UserScoreInfo.lInsureScore;
            pUserData->lWinCount=pUserInfoHead->UserScoreInfo.lWinCount;
            pUserData->lLostCount=pUserInfoHead->UserScoreInfo.lLostCount;
            pUserData->lDrawCount=pUserInfoHead->UserScoreInfo.lDrawCount;
            pUserData->lFleeCount=pUserInfoHead->UserScoreInfo.lFleeCount;
            pUserData->lExperience=pUserInfoHead->UserScoreInfo.lExperience;

            //for ( WORD wPropID = 0; wPropID < PROPERTY_COUNT; ++wPropID )
            //{
                //pUserData->dwPropResidualTime[wPropID] = pUserInfoHead->dwPropResidualTime[wPropID];
            //}

            //读取扩展信息
            void * pDataBuffer=NULL;
            tagDataDescribe DataDescribe;
            CRecvPacketHelper RecvPacket(pUserInfoHead+1,wDataSize-sizeof(tagUserInfoHead));
            while (true)
            {
                pDataBuffer=RecvPacket.GetData(DataDescribe);
                if (DataDescribe.wDataDescribe==DTP_NULL) break;
                switch (DataDescribe.wDataDescribe)
                {
                case DTP_USER_ACCOUNTS:		//用户帐户
                    {
                        if (DataDescribe.wDataSize<=sizeof(pUserData->szName))
                        {
                            CopyMemory(&pUserData->szName,pDataBuffer,DataDescribe.wDataSize);
                            //pUserData->szName[sizeof(pUserData->czNickName)-1]=0;
                        }
                        break;
                    }
                case DTP_UNDER_WRITE:		//个性签名
                    {
                        if (DataDescribe.wDataSize<=sizeof(pUserData->szUnderWrite))
                        {
                            CopyMemory(&pUserData->szUnderWrite,pDataBuffer,DataDescribe.wDataSize);
                            //pUserData->szUnderWrite[CountArray(UserData.szUnderWrite)-1]=0;
                        }
                        break;
                    }
                case DTP_USER_GROUP_NAME:	//用户社团
                    {
                        if (DataDescribe.wDataSize<=sizeof(pUserData->szGroupName))
                        {
                            CopyMemory(&pUserData->szGroupName,pDataBuffer,DataDescribe.wDataSize);
                            //pUserData->szGroupName[CountArray(UserData.szGroupName)-1]=0;
                        }
                        break;
                    }
                case DTP_USER_COMPANION:	//用户关系
                    {
                        if (DataDescribe.wDataSize<=sizeof(pUserData->cbCompanion))
                        {
                            CopyMemory(&pUserData->cbCompanion,pDataBuffer,DataDescribe.wDataSize);
                        }
                        break;
                    }
                //case DTP_USER_NICKNAME:		//用户昵称
                //    {
                //        if (DataDescribe.wDataSize<=sizeof(pUserData->czNickName))
                //        {
                //            CopyMemory(&pUserData->szNickName,pDataBuffer,DataDescribe.wDataSize);
                //        }
                //        break;
                //    }
                }
            }

            //增加用户
            ActiveUserItem(pUserData);

            return true;
        }
    case IPC_SUB_USER_STATUS:	//用户状态
        {
            //效验参数


            if (wDataSize<sizeof(IPC_UserStatus)) return false;

            //消息处理
            IPC_UserStatus * pUserStatus=(IPC_UserStatus *)pIPCBuffer;
            if (pUserStatus->cbUserStatus<US_SIT) 
            {
                if (pUserStatus->dwUserID==m_dwUserID)
                {
                    ResetClientKernel();
                    return true;
                }
                else
                           
                DeleteUserItem(pUserStatus->dwUserID);
            }
            else 
                UpdateUserItem(pUserStatus->dwUserID,pUserStatus->cbUserStatus,pUserStatus->wNetDelay);

            return true;
        }
    case IPC_SUB_USER_SCORE:	//用户积分
        {
            //效验参数

            if (wDataSize<sizeof(IPC_UserScore)) return false;

            //消息处理
            IPC_UserScore * pUserScore=(IPC_UserScore *)pIPCBuffer;

            //tagUserData *pUserData = SearchUserItem(pUserScore->dwUserID);
            //pUserData->dwLoveliness = pUserScore->UserScore->dwLoveliness;

            UpdateUserItem(pUserScore->dwUserID,&pUserScore->UserScore);

            return true;
        }
    //case IPC_SUB_MEMBERORDER:	//会员等级
    //    {
    //        //效验参数
    //        if (wDataSize<sizeof(IPC_MemberOrder)) return false;

    //        //消息处理
    //        IPC_MemberOrder * pMemberOrder=(IPC_MemberOrder *)pIPCBuffer;
    //        tagUserData *pUserData = SearchUserItem(pMemberOrder->dwUserID);
    //        pUserData->cbMemberOrder = pMemberOrder->cbMember;

    //        //更新界面
    //        m_pIClientKernelSink->OnEventUserMemberOrder(pUserData,pUserData->wChairID,false);

    //        return true;
    //    }
    case IPC_SUB_GAME_START:	//游戏开始
        {
            //设置用户
            for (WORD i=0;i<m_ServerAttribute.wChairCount;i++)
            {
                if (m_pUserItem[i]!=NULL) 
                {
                    m_pUserItem[i]->cbUserStatus=US_PLAY;
                    m_pIClientKernelSink->OnEventUserStatus(m_pUserItem[i],m_pUserItem[i]->wChairID,false);
                }
            }

            return true;
        }
    case IPC_SUB_GAME_FINISH:	//游戏结束
        {
            //设置用户
            for (WORD i=0;i<m_ServerAttribute.wChairCount;i++)
            {
                if (m_pUserItem[i]!=NULL)
                {
                    m_pUserItem[i]->cbUserStatus=US_SIT;
                    m_pIClientKernelSink->OnEventUserStatus(m_pUserItem[i],m_pUserItem[i]->wChairID,false);
                }
            }

            return true;
        }
    //case IPC_SUB_UPDATE_FACE:	//更新头像
    //    {
    //        return true;
    //    }
    }

    return false;
}