Пример #1
0
void CubeSession::SendError(SessionErrorType errorCode, bool close)
{
	log_debug("sending error (fd = %u): %d", static_cast<unsigned int>(fd), errorCode);

	int code = static_cast<int>(errorCode);

	StringBuffer sb;
	Writer<StringBuffer> writer(sb);

	writer.StartObject();

	writer.String("error");
	writer.Int(errorCode);

	writer.String("message");

	if (code > SESSIONERROR_UNKNOWN) // user facing error
	{
		writer.String(UserFacingErrorMessage[_UE(errorCode)].c_str());
	}
	else
	{
		writer.String(SessionErrorMessage[errorCode].c_str());
	}

	writer.EndObject();

	SendPackage(sb.GetString());

	//                                 is SessionError
	if (close || static_cast<int>(errorCode) <= static_cast<int>(SESSIONERROR_UNKNOWN))
	{
		FlushAndClose();
	}
}
Пример #2
0
void sendPackageByTable(char * data, uint16_t len, iptable_t * ipt) {
	if( !uip_ipaddr_cmp(&ipt->ipaddr, &ipt->link) ) {
		if( data[RID_SIZE] != MESH_M ) {
			static uint16_t i;
			for( i = len-1 ; i >= RID_SIZE ; --i ) {
				// buf can be data, reverse order to not override
				buf[i+MESH_HEAD_SIZE] = data[i];
			}
			for( i = 0 ; i < RID_SIZE ; ++i ) {
				buf[i] = data[i];
			}
			buf[RID_SIZE] = MESH_M;
			memcpy(buf+PACKAGE_HEAD, &ipt->ipaddr, UID_SIZE);
			data = buf;
			len += MESH_M;
		}
	} else if( data[RID_SIZE] == MESH_M ) {
		static uint16_t i;
		for( i = PACKAGE_HEAD+MESH_HEAD_SIZE ; i < len ; ++i ) {
			data[i-MESH_HEAD_SIZE] = data[i];
		}
		len -= MESH_HEAD_SIZE;
	}
	SendPackage(data, len, &ipt->link);
}
Пример #3
0
void CRole::CityFly(std::string strKey) {
    byte package[256];
    RtlZeroMemory(package, 256);
    *(int*)(&package[0]) = 0x00000042;
    strcpy_s((char*)(&package[0x10]), 255 - 0x10, strKey.c_str());
    SendPackage((DWORD)&package[0]);
}
Пример #4
0
void CChatConnect::Proc0_GroupMan(const void* pData, size_t size)
{
    CHAT_GROUPMAN* pCgc = (CHAT_GROUPMAN*)pData;
    CHAT_CHANNELCHAT_SYNC* pCccSync = (CHAT_CHANNELCHAT_SYNC*)(pCgc + 1);
    if (pCccSync->ProtocolType != chat_channelchat)
        return;	//unexpect

    void* pSent = pCccSync + 1;
    void* pPlayersData = (BYTE*)pSent + pCccSync->sentlen;


    DWORD srcIP = GetIP();

    const size_t playercount = pCgc->wPlayerCount;
    pCgc->wPlayerCount = 0;

    if (pCgc->byHasIdentify)
    {
        tagPlusSrcInfo* pPlayers = (tagPlusSrcInfo*)(pPlayersData);
        for (size_t i = 0; i < playercount; i++)
        {
            if (g_ChannelMgr.IsSubscribed(srcIP, pPlayers[i].lnID, pCccSync->channelid))
            {
                if (pCgc->wPlayerCount < i)
                    pPlayers[pCgc->wPlayerCount] = pPlayers[i];
                ++ pCgc->wPlayerCount;
            }
        }
    }
    else
    {
        WORD* pPlayers = (WORD*)(pPlayersData);
        for (size_t i = 0; i < playercount; i++)
        {
            if (g_ChannelMgr.IsSubscribed(srcIP, (unsigned long)pPlayers[i], pCccSync->channelid))
            {
                if (pCgc->wPlayerCount < i)
                    pPlayers[pCgc->wPlayerCount] = pPlayers[i];
                ++ pCgc->wPlayerCount;
            }
        }
    }

    if (pCgc->wPlayerCount <= 0)
        return;


    size_t size2 = size - (playercount - pCgc->wPlayerCount) * (pCgc->byHasIdentify ? sizeof(tagPlusSrcInfo) : sizeof(WORD));
    pCgc->wSize = size2 - 1;

    SendPackage(pCgc, size2);
}
Пример #5
0
void CubeSession::SendSuccess()
{
	log_debug("sending success fd = %u", static_cast<unsigned int>(fd));

	StringBuffer sb;
	Writer<StringBuffer> writer(sb);

	writer.StartObject();

	writer.String("success");
	writer.Int(0);

	writer.EndObject();

	SendPackage(sb.GetString());
}
Пример #6
0
void Client::PackageReceived(char* msg,int size)
{
	int i = 0;
	for (std::vector<RequestHandler*>::iterator it = Handlers.begin(); it != Handlers.end(); it++)
	{
		
		RequestHandler* curHandler = (RequestHandler*)(*it);
		if (strstr(msg, curHandler->GetRequest()) != NULL)
		{
			i++;
			curHandler->Handle(this,msg);
		}
	}
	if (i <= 0)
	{
		printf("No handlers found to handle : ");
		printf(msg);
		printf("\n");
		SendPackage("ERROR");
	}
}
Пример #7
0
void sendPackage(const uint8_t * data, uint16_t len, const uip_ipaddr_t * ip) {
	SendPackage(data,len,ip);
}
Пример #8
0
bool Client::SendPackage(char* msg)
{
	return SendPackage(msg, -1);
}