Beispiel #1
0
void Fwd_ParseCommands(cluster_t *cluster, oproxy_t *prox)
{
	netmsg_t buf;
	int packetlength;
	int bytes;
	bytes = NET_WebSocketRecv(prox->sock, &prox->websocket, prox->inbuffer+prox->inbuffersize, sizeof(prox->inbuffer)-prox->inbuffersize, NULL);
	if (bytes < 0)
	{
		if (qerrno != EWOULDBLOCK && qerrno != EAGAIN)	//not a problem, so long as we can flush it later.
		{
			Sys_Printf(cluster, "network error from client proxy\n");
			prox->drop = true;	//drop them if we get any errors
			return;
		}
		bytes = 0;
	}
	else if (bytes == 0)
	{
		prox->drop = true;
		return;
	}

	prox->inbuffersize += bytes;

	for(;;)
	{
		if (prox->inbuffersize < 2)	//we do need at least 3 bytes for anything useful
			break;

		packetlength = prox->inbuffer[0] + (prox->inbuffer[1]<<8);
		if (packetlength+2 > prox->inbuffersize)
			break;

		InitNetMsg(&buf, prox->inbuffer+2, packetlength);
		buf.cursize = packetlength;

		while(buf.readpos < buf.cursize)
		{
			switch (ReadByte(&buf))
			{
			case qtv_clc_stringcmd:
				{
					char stringbuf[1024];
					ReadString(&buf, stringbuf, sizeof(stringbuf));
					QTV_Printf(prox->stream, "ds: %s\n", stringbuf);
				}
			
				break;
			default:
				Sys_Printf(cluster, "Received unrecognized packet type from downstream proxy.\n");
				buf.readpos = buf.cursize;
				break;
			}
		}
		packetlength+=2;
		memmove(prox->inbuffer, prox->inbuffer+packetlength, prox->inbuffersize - packetlength);
		prox->inbuffersize -= packetlength;
	}
}
Beispiel #2
0
void ClientInit()
{
	 InitNetMsg();

	 for (int32 i = 0; i < MAX_CLIENT_COUNT; ++i)
	 {
		 NetClient* gNetClient = new NetClient();
		 gNetClient->SetAddress("127.0.0.1", 9900);
		 gNetClient->SetHandler(OnNetMsgEnter, OnNetMsg, OnNetMsgExit);
		 gNetClient->Start();

		 ClientPlayer* gPlayer = new ClientPlayer();
		 gPlayer->SetSocket(gNetClient->GetSocket());

         ClientPlayerMgr::Instance()->AddSocket(gNetClient,gPlayer);
	 }

	//命令调试
	//gGameCommond.Init(gNetClient->GetSocket());
	//GameCommand::CommandHelp();

}