Beispiel #1
0
bool ProtocolME0::GameworldLogin () {
    NetworkMessage nm;

    ONThreadSafe(threadsafe);
    connectiontype = GAMEWORLD;

    //nm.AddU8(0x14);
    //nm.AddString(this->charlist[this->charlistselected]->charactername);
    //spcount ++;
    if (!strcmp(this->charlist[this->charlistselected]->charactername, "Character Manager")) {
        nm.AddU8(0x0C); // charmgr...
        nm.AddU8(0x01); // ...enter

        FILE *f = fopen((std::string("save/") + this->username + ".ous").c_str(), "r");
        ASSERTFRIENDLY(f, "It appears that savefile has mysteriously disappeared. Exiting");
        fclose(f);

    }
    else {
        nm.AddU8(0x0A); // player's creature id shall be 1
        nm.AddU32(1);

        nm.AddU8(0x32); // report bugs?
        nm.AddU8(0);
        nm.AddU8(0);

        nm.AddU8(0x64); // player teleport
        nm.AddU16(30);
        nm.AddU16(30);
        nm.AddU8(7);
        int tilesremaining = 18*14*7;
        for (int i = 0; i < 18; i ++)
            for (int j = 0; j < 14; j++) {
                printf("%d\n", tilesremaining);
                nm.AddU16(102);
                if (i == 8 && j == 6) {
                    nm.AddU16(0x0061);
                    nm.AddU32(0); // remove with this id
                    nm.AddU32(1); // creatureid -- player is 1
                    nm.AddString("Newbie");
                    nm.AddU8(25); // health
                    nm.AddU8(0); //dir
                    nm.AddU16(128); // lookid
                    nm.AddU8(50);
                    nm.AddU8(60);
                    nm.AddU8(70);
                    nm.AddU8(80);
                    nm.AddU8(0); // addons

                    nm.AddU8(0); // lightlevel
                    nm.AddU8(0); // lightcolor
                    nm.AddU16(500); // speed
                    nm.AddU8(0); // skull
                    nm.AddU8(0); // shield




                }
                tilesremaining--;
                nm.AddU16(0xFF00);
            }
        while(tilesremaining) {

            nm.AddU8(tilesremaining > 255 ? 255 : tilesremaining);
            tilesremaining -= tilesremaining > 255 ? 255 : tilesremaining;
            printf("%d\n", tilesremaining);
            nm.AddU8(0xFF);
        }
    }


    ((GM_MainMenu*)game)->DestroyCharlist();





    // by default logon is a success
    logonsuccessful = true;

    packetparsing:
    while ((signed int)(nm.GetSize())>0 && ParsePacket(&nm));
    if ((signed int)(nm.GetSize())>0) printf("++++++++++++++++++++DIDNT EMPTY UP THE NETWORKMESSAGE!++++++++++++++++++\n");

    ONThreadUnsafe(threadsafe);
    return logonsuccessful;

}
Beispiel #2
0
/****************************************************************
        FunctionName        :   Cloud_M2MDataHandle.
        Description         :   Receive cloud business data .
        xpg                 :   global context.
        Rxbuf                :   global buf struct.
        buflen              :   receive max len.
        return              :   >0 have business data,and need to 
                                   handle.
                                other,no business data.
        Add by Alex.lin     --2015-03-10
****************************************************************/
int32 Cloud_M2MDataHandle(  pgcontext pgc,ppacket pbuf /*, ppacket poutBuf*/, uint32 buflen)
{
    uint32 dTime=0,ret=0,dataLen=0;
    uint32 packetLen=0;
    pgcontext pGlobalVar=NULL;
    pgconfig pConfigData=NULL;
    int8 *username=NULL;
    int8 *password=NULL;
    uint8* pMqttBuf=NULL;
    fd_set readfd;
    int32 mqtt_fd=0;
    uint16 mqttstatus=0;
    uint8 mqttpackType=0;
    
    pConfigData = &(pgc->gc);
    pGlobalVar = pgc;
    pMqttBuf = pbuf->phead;
    
    mqttstatus = pGlobalVar->rtinfo.waninfo.mqttstatus;
    mqtt_fd = pGlobalVar->rtinfo.waninfo.m2m_socketid;
    readfd  = pGlobalVar->rtinfo.readfd;
    username = pConfigData->DID;
    password = pConfigData->wifipasscode;
    
    if( strlen(pConfigData->m2m_ip)==0 )
    {
        //GAgent_Printf( GAGENT_INFO,"M2M IP =0 IP TIME 1 %d 2%d ",pgc->rtinfo.waninfo.RefreshIPLastTime,pgc->rtinfo.waninfo.RefreshIPTime);
        return 0;
    }
    if( MQTT_STATUS_START==mqttstatus )
    {
        GAgent_Printf(GAGENT_INFO,"Req to connect m2m !");
        GAgent_Printf(GAGENT_INFO,"username: %s password: %s",username,password);

        Cloud_ReqConnect( pgc,username,password );
        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGIN );
        GAgent_Printf(GAGENT_INFO," MQTT_STATUS_START ");
        pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS();
        return 0;
    }
    dTime = abs( GAgent_GetDevTime_MS()-pGlobalVar->rtinfo.waninfo.send2MqttLastTime );
    if( FD_ISSET( mqtt_fd,&readfd )||( mqttstatus!=MQTT_STATUS_RUNNING && dTime>GAGENT_MQTT_TIMEOUT))
    {
        if( FD_ISSET( mqtt_fd,&readfd ) )
        {
          GAgent_Printf(GAGENT_DEBUG,"Data form M2M!!!");
          resetPacket( pbuf );
          packetLen = MQTT_readPacket(mqtt_fd,pbuf,GAGENT_BUF_LEN );
          if( packetLen==-1 ) 
          {
              mqtt_fd=-1;
              pGlobalVar->rtinfo.waninfo.m2m_socketid=-1;
              GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START );
              GAgent_Printf(GAGENT_DEBUG,"MQTT fd was closed!!");
              GAgent_Printf(GAGENT_DEBUG,"GAgent go to MQTT_STATUS_START");
              return -1;
          }
          else if(packetLen>0)
          {
            mqttpackType = MQTTParseMessageType( pMqttBuf );
            GAgent_Printf( GAGENT_DEBUG,"MQTT message type %d",mqttpackType );
          }
          else
          {
            return -1;
          }
        }

        /*create mqtt connect to m2m.*/
        if( MQTT_STATUS_RUNNING!=mqttstatus &&
            (MQTT_MSG_CONNACK==mqttpackType||MQTT_MSG_SUBACK==mqttpackType||dTime>GAGENT_MQTT_TIMEOUT))
        {
            switch( mqttstatus)
            {
                case MQTT_STATUS_RES_LOGIN:
                    
                     ret = Cloud_ResConnect( pMqttBuf );
                     if( ret!=0 )
                     {
                         GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_REQ_LOGIN Fail ");
                         if( dTime > GAGENT_MQTT_TIMEOUT )
                         {
                            GAgent_Printf(GAGENT_DEBUG,"MQTT req connetc m2m again!");
                            Cloud_ReqConnect( pgc,username,password );
                         }
                     }
                     else
                     {
                         GAgent_Printf(GAGENT_DEBUG,"GAgent do req connect m2m OK !");
                         GAgent_Printf(GAGENT_DEBUG,"Go to MQTT_STATUS_REQ_LOGINTOPIC1. ");
                         Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC1 );
                         GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC1 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC1:
                     ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( 0!=ret )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC1 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf( GAGENT_DEBUG,"GAgent req sub LOGINTOPIC1 again ");
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC1 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_DEBUG,"Go to MQTT_STATUS_RES_LOGINTOPIC2. ");
                        Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC2 );
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC2 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC2:
                     ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( 0 != ret )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC2 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf( GAGENT_INFO,"GAgent req sub LOGINTOPIC2 again.");
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC2 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_DEBUG," Go to MQTT_STATUS_RES_LOGINTOPIC3. ");
                        Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC3 );
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC3 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC3:
                      ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( ret != 0 )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC3 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf(GAGENT_DEBUG,"GAgent req sub LOGINTOPIC3 again." );
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC3 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_CRITICAL,"GAgent Cloud Working...");
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RUNNING );
                        GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_STATUS,0 );
                     }
                      break;
                default:
                     break;
            }
            pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS();  
        }
        else if( packetLen>0 && ( mqttstatus == MQTT_STATUS_RUNNING ) )
        {
            int varlen=0,p0datalen=0;
            switch( mqttpackType )
            {
                case MQTT_MSG_PINGRESP:
                    pgc->rtinfo.waninfo.cloudPingTime=0;
                    GAgent_Printf(GAGENT_INFO,"GAgent MQTT Pong ... \r\n");
                break;
                case MQTT_MSG_PUBLISH:
                    dataLen = Mqtt_DispatchPublishPacket( pgc,pMqttBuf,packetLen );
                    if( dataLen>0 )
                    {
                        pbuf->type = SetPacketType( pbuf->type,CLOUD_DATA_IN,1 );
                        ParsePacket(  pbuf );
                        GAgent_Printf(GAGENT_INFO,"%s %d type : %04X len :%d",__FUNCTION__,__LINE__,pbuf->type,dataLen );
                    }
                break;
                default:
                    GAgent_Printf(GAGENT_WARNING," data form m2m but msg type is %d",mqttpackType );
                break;
            }
        }
    }
    return dataLen;
}
Beispiel #3
0
bool ProtocolME0::CharlistLogin(const char *username, const char *password) {
    NetworkMessage nm;

    ONThreadSafe(threadsafe);
    connectiontype = CHARLIST;

    this->username = username;
    this->password = password;

    FILE *f = fopen((std::string("save/") + username + ".ous").c_str(),"r");
    if (!f) {
        FILE *fo = fopen((std::string("save/") + username + ".ous").c_str(),"w");
        if (!fo) {
            nm.AddU8(0x0A);
            nm.AddString("You need write permissions on save/ subfolder of \nThe Outcast to start a local game.");
            goto packetparsing;
        } else {
            fprintf(fo, "%s\n", password);
            fclose(fo);
            f = fopen((std::string("save/") + username + ".ous").c_str(),"r");

        }
    }

    {
        char filepwd[255];
        fscanf(f, "%s", filepwd);

        if (strcmp(filepwd, password)) {
            nm.AddU8(0x0A);
            nm.AddString("You entered incorrect password.");
        } else {
            char charname[255];

            nm.AddU8(0x14);
            nm.AddString("7435\nWelcome to Clavicula, a singleplayer mode for The Outcast!\n\nClavicula is an attempt to create a singleplayer game \nsimilar to Tibia. To create a character, choose Character\nManager option from the character list.");
            nm.AddU8(0x64);

            int pos = ftell(f);
            int spcount = 0;
            while (fscanf(f, "%s", charname)==1) spcount ++;
            fseek(f, pos, SEEK_SET);
            nm.AddU8(1 + spcount); // one character is CREATE CHARACTER, others are temp count to make dynamic list
            nm.AddString("Character Manager");
            nm.AddString("Clavicula");
            nm.AddU32(0); // ip address
            nm.AddU16(0); // port


            while (fscanf(f, "%s", charname)==1)  {
                nm.AddString(charname);
                nm.AddString("Clavicula");
                nm.AddU32(0); // ip address
                nm.AddU16(0); // port
            }

            nm.AddU16(0); // free account
        }
    }

    // by default logon is a success
    logonsuccessful = true;

    packetparsing:
    while ((signed int)(nm.GetSize())>0 && ParsePacket(&nm));
    if ((signed int)(nm.GetSize())>0) printf("++++++++++++++++++++DIDNT EMPTY UP THE NETWORKMESSAGE!++++++++++++++++++\n");

    ONThreadUnsafe(threadsafe);
    return logonsuccessful;
}
Beispiel #4
0
void CMLan::OnRecvPacket(u_char* mes, int len, in_addr from)
{
	EnterCriticalSection(&m_csReceiveThreadLock);

	if (len)
	{
		TPacket pak;
		ParsePacket(pak, mes, len);

		if (pak.idVersion!=0)
		{
			TContact* cont = m_pRootContact;
			while (cont)
			{
				if (cont->m_addr.S_un.S_addr == from.S_un.S_addr)
					break;
				cont = cont->m_prev;
			}
			if (pak.idStatus)
			{
				EnterCriticalSection(&m_csAccessClass);
				if (!cont)
				{
					if (!pak.strName)
						pak.strName = "Unknown";
					cont = new TContact;
					cont->m_addr = from;
					cont->m_prev = m_pRootContact;
					cont->m_status = ID_STATUS_OFFLINE;
					int nlen = (int)strlen(pak.strName);
					cont->m_nick = new char[nlen+1];
					CopyMemory(cont->m_nick, pak.strName, nlen+1);
					m_pRootContact = cont;
				}
				else
				{
					if (pak.strName && strcmp(pak.strName, cont->m_nick)!=0)
					{
						delete[] cont->m_nick;
						int nlen = (int)strlen(pak.strName);
						cont->m_nick = new char[nlen+1];
						CopyMemory(cont->m_nick, pak.strName, nlen+1);
					}
				}
				cont->m_time = MLAN_CHECK + MLAN_TIMEOUT;
				cont->m_ver = pak.idVersion;
				u_int old_status = cont->m_status;
				cont->m_status = pak.idStatus;
				MCONTACT hContact = FindContact(cont->m_addr, cont->m_nick, false, false, false);
				if (hContact)
				{
					db_set_w(hContact,PROTONAME, "Status", cont->m_status);
					if (db_get_dw(hContact,PROTONAME, "RemoteVersion", 0)!=cont->m_ver)
								db_set_dw(hContact,PROTONAME, "RemoteVersion", cont->m_ver);
					if (old_status == ID_STATUS_OFFLINE)
					{
						u_int rip = cont->m_addr.S_un.S_addr;
						int tip = (rip<<24)|((rip&0xff00)<<8)|((rip&0xff0000)>>8)|(rip>>24);
						db_set_dw(hContact, PROTONAME, "IP", tip);
//						HOSTENT* host = gethostbyaddr((const char*)&rip, sizeof(rip), AF_INET);
//						if (host)
//							db_set_s(hContact, PROTONAME, "UID", host->h_name);
					}
				}
				LeaveCriticalSection(&m_csAccessClass);
			}
Beispiel #5
0
DemuxPacket* CDVDDemuxClient::Read()
{
  if (!m_IDemux)
    return nullptr;

  if (m_packet)
    return m_packet.release();

  m_packet.reset(m_IDemux->ReadDemux());
  if (!m_packet)
  {
    return nullptr;
  }

  if (m_packet->iStreamId == DMX_SPECIALID_STREAMINFO)
  {
    RequestStreams();
    CDVDDemuxUtils::FreeDemuxPacket(m_packet.release());
    return CDVDDemuxUtils::AllocateDemuxPacket(0);
  }
  else if (m_packet->iStreamId == DMX_SPECIALID_STREAMCHANGE)
  {
    RequestStreams();
  }
  else if (m_packet->iStreamId >= 0 && m_streams.count(m_packet->iStreamId) > 0)
  {
    if (ParsePacket(m_packet.get()))
    {
      RequestStreams();
      DemuxPacket *pPacket = CDVDDemuxUtils::AllocateDemuxPacket(0);
      pPacket->iStreamId = DMX_SPECIALID_STREAMCHANGE;
      pPacket->demuxerId = m_demuxerId;
      return pPacket;
    }
  }

  if (!IsVideoReady())
  {
    m_packet.reset();
    DemuxPacket *pPacket = CDVDDemuxUtils::AllocateDemuxPacket(0);
    pPacket->demuxerId = m_demuxerId;
    return pPacket;
  }

  //! @todo drop this block
  CDVDInputStream::IDisplayTime *inputStream = m_pInput->GetIDisplayTime();
  if (inputStream)
  {
    int dispTime = inputStream->GetTime();
    if (m_displayTime != dispTime)
    {
      m_displayTime = dispTime;
      if (m_packet->dts != DVD_NOPTS_VALUE)
      {
        m_dtsAtDisplayTime = m_packet->dts;
      }
    }
    if (m_dtsAtDisplayTime != DVD_NOPTS_VALUE && m_packet->dts != DVD_NOPTS_VALUE)
    {
      m_packet->dispTime = m_displayTime;
      m_packet->dispTime += DVD_TIME_TO_MSEC(m_packet->dts - m_dtsAtDisplayTime);
    }
  }

  return m_packet.release();
}
uint32 GAgent_LocalDataHandle( pgcontext pgc,ppacket Rxbuf,int32 RxLen /*,ppacket Txbuf*/ )
{
    int8 cmd=0;
    uint8 sn=0,checksum=0;
    uint8 *localRxbuf=NULL;
    uint32 ret = 0;
    uint8 configType=0;
    _tm tm;
    if( RxLen>0 )
    {
        localRxbuf = Rxbuf->phead;
        
        cmd = localRxbuf[4];
        sn  = localRxbuf[5];
        checksum = GAgent_SetCheckSum( localRxbuf,RxLen-1 );
        if( checksum!=localRxbuf[RxLen-1] )
        {
            GAgent_Printf( GAGENT_ERROR,"local data cmd=%02x checksum error !",cmd );
            GAgent_DebugPacket(Rxbuf->phead, RxLen);
            return 0;
        }

        switch( cmd )
        {
            case MCU_REPORT:
                Local_Ack2MCU( pgc->rtinfo.local.uart_fd,sn,cmd+1 );
                Rxbuf->type = SetPacketType( Rxbuf->type,LOCAL_DATA_IN,1 );
                ParsePacket( Rxbuf );
                ret = 1;
                break;
            case MCU_CONFIG_WIFI:
                Local_Ack2MCU( pgc->rtinfo.local.uart_fd,sn,cmd+1 );
                configType = localRxbuf[8];
                GAgent_Config( configType,pgc );
                ret = 0;
                break;
            case MCU_RESET_WIFI:
                Local_Ack2MCU( pgc->rtinfo.local.uart_fd,sn,cmd+1 );
                GAgent_Clean_Config(pgc);
                sleep(2);
                GAgent_DevReset();
                ret = 0;
                break;
            case WIFI_PING2MCU_ACK:
                pgc->rtinfo.local.timeoutCnt=0;
                GAgent_Printf( GAGENT_CRITICAL,"Local pong...");
                ret = 0 ;
                break;
            case MCU_CTRL_CMD_ACK:
                ret = 0;
                break;
            case WIFI_TEST:
                Local_Ack2MCU( pgc->rtinfo.local.uart_fd,sn,cmd+1 );
                GAgent_EnterTest( pgc );
                ret = 0;
                break;
            case MCU_ENABLE_BIND:
                Local_Ack2MCU( pgc->rtinfo.local.uart_fd,sn,cmd+1 );
                pgc->mcu.passcodeTimeout = pgc->mcu.passcodeEnableTime;
                GAgent_SetWiFiStatus( pgc,WIFI_MODE_BINDING,1 );	
                ret = 0;
                break;
            case MCU_REQ_GSERVER_TIME:	                                                                                            
                tm = GAgent_GetLocalTimeForm(pgc->rtinfo.clock);
                *(uint16 *)(Rxbuf->ppayload) = htons(tm.year);
                Rxbuf->ppayload[2] = tm.month;
                Rxbuf->ppayload[3] = tm.day;
                Rxbuf->ppayload[4] = tm.hour;
                Rxbuf->ppayload[5] = tm.minute;
                Rxbuf->ppayload[6] = tm.second;
                Rxbuf->pend = (Rxbuf->ppayload) + 7;
                Local_Ack2MCUwithP0( Rxbuf, pgc->rtinfo.local.uart_fd, sn, MCU_REQ_GSERVER_TIME_ACK );
                ret = 0;
                break;
            default:
                ret = 0;
                break;
        }
        //...
    }

  return ret;
}
Beispiel #7
0
void Comm_Task(void *param)
{
	uint8_t buf_rec[BUFSIZE], i;
	uint16_t cnt = 0;
	
	static uint16_t datasize = 0;
	
	// init rs485
  	InitRS(USART1, 115200, e8N1, 100);
	
	while (1)
	{
		if (Read(buf_rec + datasize, 1) == 1)
		{
		  	++datasize;
			
			if (datasize == 1)	// address verification
			{
				  if (buf_rec[0] == (uint8_t)slave_addr)
				  {
					buf_rec[1] = BUFSIZE;	// temporary maximum packet length 
					memset(buf_rec + 2, 0, BUFSIZE - 2);
				  }
				  else
					datasize = 0;
			}
			else if (datasize == 2)	// reception id
			{
			  	datasize = datasize;
			}
			else if (datasize == 3) // receiving a packet length
			{
			  if ((buf_rec[2] > BUFSIZE) || (buf_rec[2] < 4))
			  {
			  	// incorrect packet length
				datasize = 0;
			  }
			}
			else if (datasize >= buf_rec[2])
			{	
			  	uint16_t n = buf_rec[2] - 1;

				// checksum is OK?
				if (Crc8(buf_rec, n) == buf_rec[n])
				{
					// parser packet
				 	memcpy(buf_tr, buf_rec, buf_rec[2]);
					if (ParsePacket(buf_tr))
					  Write(USART1, buf_tr, buf_tr[2]);
				
					// treated to remove the package from the buffer
					datasize = 0;
				}
				else
				{
				  	// response when the checksum does not match
				  	for (i = 0; i < 1; i++)
		  				buf_tr[i] = cnt++;
		  			Write(USART1, buf_tr, 1);
					// checksum is invalid
					datasize = 0;
				}
			}
		}
		else
		{	
		  	// reception timeout
			Purge();
			datasize = 0;
		}

		taskYIELD();
	}
}
void CNetworkReceive::ReceivePacket(int sock) {
    //NOTE: this should take care of reading
    std::ofstream Log("Log.txt",std::ofstream::app);
    int32_t time_step = 5;
    int16_t playerid = 2;
    int32_t x = 1000;
    int32_t y= 500;
    int16_t action= 14;
    char buffer[512];
    int32_t packet_length = 0;
    int bytes_read = 0;
    //get length of the packet in network byte order.
    bytes_read = read(sock,&packet_length,sizeof(packet_length));


// ...


    if(bytes_read <= 0){
        #ifdef LOG_ON
            Log << "Error: Bytes received received: " << bytes_read << "\n";
            Log.flush();
            Log.close();
        #endif
        return;
    }
    if(ntohl(packet_length) <= 0){
        #ifdef LOG_ON
        Log << "Received packet advertising length of zero.\n";
        #endif
        return;
    }
    #ifdef LOG_ON
    Log << "1:Packet length received: " << ntohl(packet_length) << "\n";
    Log.flush();
    #endif
    //Allocate buffer of the size of the message
    char message_buffer[ntohl(packet_length)+1];
    //We need to write the length into the message buffer(in network byte order), as it'll be needed later.
    *(int32_t*)(message_buffer) = packet_length;
    packet_length = ntohl(packet_length);
    //Let's read the rest of the packet.
    #ifdef LOG_ON
    Log << "2:Reading the packet.\n";
    Log.flush();
    #endif
    //Let's make sure the entire message is on the
    while(bytes_read < packet_length){
        int read_result = read(sock,message_buffer+bytes_read, packet_length-bytes_read);
        if(read_result < 0){
            #ifdef LOG_ON
            Log << "Error reading packet from socket\n";
            #endif
            return;
        } else {
            bytes_read += read_result;
        }
    }
    //send packet to be decoded
    #ifdef LOG_ON
    Log << "3:Parsing packet of length:" << bytes_read << "\n";
    Log.flush();
    Log.close();
    #endif
    Log << "timestep# " << ntohl(*(int32_t*)(message_buffer+6)) << "\n";
    ParsePacket(message_buffer, packet_length);

}
Beispiel #9
0
void HandleDataRecv(int i, SOCKET sck, LPARAM lParam) {
	int bnetlen;
	char asdf[256];

	if (LOWORD(lParam) == FD_READ) {
		if (loglevel > 2)
			AddChatf(asdf, hWnd_status_re, 0xFFC080, "FD_READ event on %d", i);
		if ((bot[i]->fstate & BFS_USEPROXY) && !(bot[i]->fstate & BFS_FIRSTDATARX)) {
			HandleProxyResponse(i, sck);
			bot[i]->fstate |= BFS_FIRSTDATARX;
			ContinueConnectProcess(i);
			return;
		}
		int tmp = recv(sck, bot[i]->wsdata + bot[i]->recvlen,
			sizeof(bot[i]->wsbuffer) - (bot[i]->wsdata - bot[i]->wsbuffer) - bot[i]->recvlen, 0);
		if (tmp == SOCKET_ERROR) {
			sprintf(asdf, "recv() error %d!", WSAGetLastError());
			AddChat(vbRed, asdf, bot[i]->hWnd_rtfChat);
			return;
		} else if (!tmp) {
			AddChat(vbRed, "recv() returned 0!", bot[i]->hWnd_rtfChat);
			DisconnectProfile(i, false);
			return;
		}
		bot[i]->recvlen += tmp;

		while (bot[i]->recvlen >= 4) {
			if ((unsigned char)*bot[i]->wsdata != (unsigned char)0xFF) {
				sprintf(asdf, "[BNET] Parse error! expected 0xFF, 0x%02x.", (unsigned char)*bot[i]->wsdata);
				AddChat(vbRed, asdf, bot[i]->hWnd_rtfChat);
				bot[i]->wsdata  = bot[i]->wsbuffer;
				bot[i]->recvlen = 0;
				return;
			}

			bnetlen = *(unsigned short *)(bot[i]->wsdata + 2);
			if (bnetlen > bot[i]->recvlen) {
				sprintf(asdf, "[BNET] Expecting %d more bytes.", bnetlen - bot[i]->recvlen);
				AddChat(vbYellow, asdf, bot[i]->hWnd_rtfChat);
				if (bot[i]->wsdata + bot[i]->recvlen >= bot[i]->wsbuffer + sizeof(bot[i]->wsbuffer)) {
					memcpy(bot[i]->wsbuffer, bot[i]->wsdata, bot[i]->recvlen);
					bot[i]->wsdata = bot[i]->wsbuffer;
				}
				return;
			}
#if 0
			int bleep, i2, i3;							 
			bleep = 0;
			i3 = 0;
			for (i2 = 0; i2 != bnetlen; i2++) {
				i3++;
				bleep += bot[i]->wsdata[i2] << 1;
				if (i3 == 5) {
					Beep((bleep << 3) + 300, 25);
					i3 = 0;
					bleep = 0;
				}
			}
#endif
			ParsePacket(bot[i]->wsdata[1], bot[i]->wsdata, i);
			bot[i]->recvcount++;
			bot[i]->recvlen -= bnetlen;
			bot[i]->wsdata  += bnetlen;
		}

		bot[i]->wsdata  = bot[i]->wsbuffer;
		bot[i]->recvlen = 0;
	} else {
		if (LOWORD(lParam) == FD_CLOSE) {
			if (loglevel > 2)
				AddChatf(asdf, hWnd_status_re, 0xFFC080, "FD_CLOSE event on %d", i);

			AddChat(vbRed, "[BNET] Winsock Close.", bot[i]->hWnd_rtfChat);
			bnetlen = HIWORD(lParam);
			if (bnetlen) {
				sprintf(asdf, "[BNET] Winsock Error %d !", bnetlen);
				AddChat(vbRed, asdf, bot[i]->hWnd_rtfChat);
				sprintf(asdf, "Winsock error %d encountered on profile %d!", bnetlen, i);
				PopupTrayMsg("Connection dropped!", asdf, NIIF_ERROR);
			}
			DisconnectProfile(i, false);  
			AutoReconnectStart(i, 0);
			return;	
		} else if (LOWORD(lParam) == FD_CONNECT) {
			if (loglevel > 2)
				AddChatf(asdf, hWnd_status_re, 0xFFC080, "FD_CONNECT event on %d", i);
		
			int err = WSAGETSELECTERROR(lParam);	
			if (err) {
				AddChatf(asdf, bot[i]->hWnd_rtfChat, vbRed,
					"Connection failed, error %d!", err);
				DisconnectProfile(i, false);
				AutoReconnectStart(i, 0);
				return;
			}
			ContinueConnectProcess(i);
		}
	}
	return;						  
}
Beispiel #10
0
void SolarEdgeBase::ParseData(const unsigned char *pData, int Len)
{
	while (Len>0)
	{
		switch (m_state)
		{
		case E_WAITING_SYNC:
			if (m_bufferpos==0)
			{
				if (pData[0]==SYNC_BYTE_1)
				{
					m_RXBuffer[m_bufferpos++]=pData[0];
				}
			}
			else if (m_bufferpos==1)
			{
				if (pData[0]==SYNC_BYTE_2)
				{
					m_RXBuffer[m_bufferpos++]=pData[0];
				}
				else
					m_bufferpos=0;
			}
			else if (m_bufferpos==2)
			{
				if (pData[0]==SYNC_BYTE_3)
				{
					m_RXBuffer[m_bufferpos++]=pData[0];
				}
				else
					m_bufferpos=0;
			}
			else if (m_bufferpos==3)
			{
				if (pData[0]==SYNC_BYTE_4)
				{
					m_RXBuffer[m_bufferpos++]=pData[0];
					m_state=E_WAITING_LENGTH;
				}
				else
					m_bufferpos=0;
			}
			break;
		case E_WAITING_LENGTH:
			m_RXBuffer[m_bufferpos++]=pData[0];
			if (m_bufferpos==6)
			{
				//Length here
				m_wantedlength=(m_RXBuffer[5]<<8)|m_RXBuffer[4];
				if (m_wantedlength>1000)
				{
					//For sure something wrong here!
					m_bufferpos=0;
					m_state=E_WAITING_SYNC;
				}
				else
				{
					m_wantedlength+=(16+6);
					m_state=E_WAITING_DATA;
				}
			}
			break;
		case E_WAITING_DATA:
			m_RXBuffer[m_bufferpos++]=pData[0];
			if (m_bufferpos==m_wantedlength)
			{
				unsigned short ret=ParsePacket((unsigned char*)&m_RXBuffer,m_wantedlength);
				m_state = E_WAITING_SYNC;
				m_bufferpos=0;
			}
			break;
		}
		pData++;
		Len--;
	}
}
void AtmelSWIAnalyzer::WorkerThread()
{
    Setup();

	SWI_WaveParser tokenizer(mSDA, GetSampleRate());

	Frame frm;

	U64 SampleBegin, SampleEnd;
	SWI_Token token;

	if (mSettings.mDecodeLevel == DL_Tokens)
	{
		// just read all the tokens
		for (;;)
		{
			token = tokenizer.GetToken(SampleBegin, SampleEnd);
			
			AddFrame(SampleBegin, SampleEnd, FrameToken, token);
		}

	} else if (mSettings.mDecodeLevel == DL_Bytes) {

		// sync to the first wake token
		tokenizer.GetWake(SampleBegin, SampleEnd);

		AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);

		// now read bytes or wake tokens
		bool IsWake;
		for (;;)
		{
			U8 DataByte = tokenizer.GetByte(SampleBegin, SampleEnd, IsWake);

			if (IsWake)
				AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);
			else
				AddFrame(SampleBegin, SampleEnd, FrameByte, DataByte);
		}

	} else if (mSettings.mDecodeLevel == DL_Packets) {

		// sync to the first wake token
		tokenizer.GetWake(SampleBegin, SampleEnd);

		AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);

		// now read bytes and pack them into Flag frames and I/O blocks

		std::vector<std::pair<U64, U64> > ByteSamples;
		SWI_Block block;
		SWI_Opcode PrevOpcode = SWIO_Undefined;
		bool is_wake = false;
		U8 byte;

		for (;;)
		{
			try {
				// get the flag
				U8 Flag = tokenizer.GetByte(SampleBegin, SampleEnd, is_wake);

				if (is_wake)
				{
					AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);
					throw WakeException();
				} else if (Flag == SWIF_Command  ||  Flag == SWIF_Transmit  ||  Flag == SWIF_Idle  ||  Flag == SWIF_Sleep) {
					AddFrame(SampleBegin, SampleEnd, FrameFlag, Flag, 1);
				} else {
					// add the error flag
					AddFrame(SampleBegin, SampleEnd, FrameFlag, Flag, 0);

					ResyncToWake(tokenizer);
				}

				// read the I/O block after the command or transmit flags
				if (Flag == SWIF_Command  ||  Flag == SWIF_Transmit)
				{
					ByteSamples.clear();
					block.Clear();

					// set the block opcode
					block.IsCommand = (Flag == SWIF_Command);
					if (!block.IsCommand)
						block.Opcode = PrevOpcode;

					// read the block byte count
					U8 Count = tokenizer.GetByte(SampleBegin, SampleEnd, is_wake);

					if (is_wake)
					{
						AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);
						throw WakeException();
					}

					block.Data.push_back(Count);
					ByteSamples.push_back(std::make_pair(SampleBegin, SampleEnd));

					// we can't have a block without a data packet of at least
					// one byte meaning the block has to be at least 4 bytes long
					if (Count < 4)
						ResyncToWake(tokenizer);

					// read the bytes of the IO block
					int c;
					for (c = 0; c < Count - 1; c++)
					{
						byte = tokenizer.GetByte(SampleBegin, SampleEnd, is_wake);
						if (is_wake  &&  !ByteSamples.empty())
						{
							// make raw byte frames from the data read so far
							std::vector<std::pair<U64, U64> >::const_iterator bs_i(ByteSamples.begin());
							std::vector<U8>::const_iterator di(block.Data.begin());
							while (bs_i != ByteSamples.end())
							{
								AddFrame(bs_i->first, bs_i->second, FrameByte, *di);

								++di;
								++bs_i;
							}

							// add the wake token
							AddFrame(SampleBegin, SampleEnd, FrameToken, SWI_Wake);

							throw WakeException();
						}

						block.Data.push_back(byte);
						ByteSamples.push_back(std::make_pair(SampleBegin, SampleEnd));
					}

					// set the opcode in the block object
					if (block.IsCommand)
						block.Opcode = static_cast<SWI_Opcode>(block.Data[1]);

					// Add the Count frame
					AddFrame(ByteSamples.front().first, ByteSamples.front().second, FrameCount, Count);

					// add the block to the container
					size_t block_ndx = mResults->AddBlock(block);

					// parse the packet data
					ParsePacket(block, block_ndx, ByteSamples);

					// Add the checksum frame
					AddFrame((ByteSamples.end() - 2)->first, ByteSamples.back().second,
								FrameChecksum,
								block.GetChecksum(),
								block.CalcCRC());

					// remember the command for the next iteration
					if (block.IsCommand)
						PrevOpcode = block.Opcode;
					else
						PrevOpcode = SWIO_Undefined;
				}

			} catch (WakeException&) {
				// Just ignore the wake token. The exception thrown on an unexpected
				// wake token will only re-sync the parser to the next flag.
			}
		}
	}
}
Beispiel #12
0
void ParsePacket(const CPacket_Read &cPacket, bool bFirst, char *aMsgBuff, uint32 nBufferSize, uint8 nTravelDir = NETMGR_TRAVELDIR_UNKNOWN)
{
	// Parse the incoming packet...
	if(!aMsgBuff) 
		return;

	CPacket_Read cParsePacket(cPacket);


	// We need a buffer to stuff this into..
	char aTemp[256];

	if(bFirst)
	{
		memset(aMsgBuff, 0, sizeof(aMsgBuff));
	}

	switch(nTravelDir)
	{
		case NETMGR_TRAVELDIR_SERVER2CLIENT:
			LTStrCat(aMsgBuff, (bFirst) ? "<S2C>" : "<s2c>", nBufferSize);
			break;

		case NETMGR_TRAVELDIR_CLIENT2SERVER:
			LTStrCat(aMsgBuff, (bFirst) ? "<C2S>" : "<c2s>", nBufferSize);
			break;

		case NETMGR_TRAVELDIR_UNKNOWN:
		default:
			LTStrCat(aMsgBuff, (bFirst) ? "<U2U>" : "<u2u>", nBufferSize);
			break;
	}

	uint32 nPacketID = cParsePacket.Readuint8();

	// NetMgr layer
	switch(nPacketID)
	{
		case 4 : //SMSG_NETPROTOCOLVERSION
			LTStrCat(aMsgBuff, "(NPV) ", nBufferSize);
			break;

		case 5 : //SMSG_UNLOADWORLD
			LTStrCat(aMsgBuff, "(ULW) ", nBufferSize);
			break;

		case 6 : //SMSG_LOADWORLD
			LTStrCat(aMsgBuff, "(LW )  ", nBufferSize);
			break;

		case 7 : //SMSG_CLIENTOBJECTID
			LTStrCat(aMsgBuff, "(COI) ", nBufferSize);
			break;

		case 8 : //SMSG_UPDATE
		{
			LTStrCat(aMsgBuff, "(UPD) ", nBufferSize);

			while (cParsePacket.TellEnd())
			{
				uint8 nSubLen = cParsePacket.Readuint8() * 8;
				if (!nSubLen)
					break;

				if (cParsePacket.TellEnd() < nSubLen)
				{
					LTStrCat(aMsgBuff, "BAD ", nBufferSize);
					break;
				}

				ParsePacket(CPacket_Read(cParsePacket, cParsePacket.Tell(), nSubLen), false, aMsgBuff, nTravelDir);
				cParsePacket.Seek(nSubLen);
			}

			while(cParsePacket.TellEnd())
			{
				uint32 nFlags = (uint32)cParsePacket.Readuint8();

				if(nFlags & (1<<7)) //CF_OTHER
				{
					if (cParsePacket.TellEnd() < 8)
					{
						LTStrCat(aMsgBuff, "BAD ", nBufferSize);
						break;
					}

					nFlags |= (uint32)cParsePacket.Readuint8() << 8;
				}

				if(nFlags)
				{
					if(cParsePacket.TellEnd() < 16)
					{
						LTStrCat(aMsgBuff, "BAD ", nBufferSize);
						break;
					}

					uint16 nObjectID = cParsePacket.Readuint16();
					LTSNPrintF(aTemp, sizeof(aTemp), "|%04x| ", nObjectID);
					LTStrCat(aMsgBuff, aTemp, nBufferSize);

					if (nFlags & (1<<0)) //CF_NEWOBJECT
						LTStrCat(aMsgBuff, "NEW ", nBufferSize);
					else
					{
						if ( nFlags & ((1<<5)|(1<<13)) ) //CF_MODELINFO|CF_FORCEMODELINFO
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "MI  |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & (1<<3)) //CF_FLAGS
						{
							LTStrCat(aMsgBuff, "FLG ", nBufferSize);
							if (cParsePacket.TellEnd() < 80)
							{
								LTStrCat(aMsgBuff, "BAD ", nBufferSize);
								break;
							}

							uint32 nFlags1 = cParsePacket.Readuint32();
							uint16 nFlags2 = cParsePacket.Readuint16();
							uint32 nUserFlags = cParsePacket.Readuint32();
							LTSNPrintF(aTemp, sizeof(aTemp), "|%08hx %04hx %08x| ", nFlags1, (uint16)nFlags2, nUserFlags);
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
						}
						if (nFlags & (1<<6)) //CF_COLORINFO
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "CLR |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & (1<<4)) //CF_SCALE
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "SCL |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & ((1<<1)|(1<<9))) //(CF_POSITION|CF_TELEPORT)
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "POS |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & ((1<<2)|(1<<10))) //(CF_ROTATION|CF_SNAPROTATION)
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "ROT |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & (1<<8)) //CF_ATTACHMENTS
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "ATT |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
						if (nFlags & (1<<11)) //CF_FILENAMES
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "FILEN |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
						}
					}
				}
				else
				{
					if(cParsePacket.TellEnd() < 8)
					{
						LTStrCat(aMsgBuff, "BAD ", nBufferSize);
						break;
					}

					uint8 nType = cParsePacket.Readuint8();

					switch(nType)
					{
						case 0 : //UPDATESUB_PLAYSOUND
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "SND |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
							break;
						}
						case 1 : //UPDATESUB_SOUNDTRACK
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "STK |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
							break;
						}
						case 3 : //UPDATESUB_OBJECTREMOVES
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "REM |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
							break;
						}
						default :
						{
							LTSNPrintF(aTemp, sizeof(aTemp), "UNK |%d| ", cParsePacket.TellEnd());
							LTStrCat(aMsgBuff, aTemp, nBufferSize);
							cParsePacket.SeekTo(cParsePacket.Size());
							break;
						}
					}
				}
			}
			break;
		}

		case 0xA : //SMSG_UNGUARANTEEDUPDATE
		{
			LTStrCat(aMsgBuff, "(UUP) ", nBufferSize);
			LTSNPrintF(aTemp, sizeof(aTemp), "|%d| ", cParsePacket.TellEnd() / 8);
			LTStrCat(aMsgBuff, aTemp, nBufferSize);
			break;
		}

		case 0xC : //SMSG_YOURID
			LTStrCat(aMsgBuff, "(YID) ", nBufferSize);
			break;

		case 0xB : //CMSG_MESSAGE
		case 0xD : //SMSG_MESSAGE
		{
			LTStrCat(aMsgBuff, "(MSG) ", nBufferSize);
			if (cParsePacket.TellEnd() < 8)
			{
				LTStrCat(aMsgBuff, "BAD ", nBufferSize);
				break;
			}
			// Strip the message ID off the end
			CPacket_Read cSubPacket(cParsePacket, cParsePacket.Tell(), cParsePacket.TellEnd() - 8);
			cParsePacket.Seek(cSubPacket.Size());
			uint8 nMsgID = cParsePacket.Readuint8();
			cParsePacket = cSubPacket;
			switch (nMsgID)
			{
				case 100 : // MID_PLAYER_UPDATE
				{
					LTSNPrintF(aTemp, sizeof(aTemp), "[PLU] |%d| ", cParsePacket.TellEnd());
					LTStrCat(aMsgBuff, aTemp, nBufferSize);

					if (cParsePacket.TellEnd() < 16)
					{
						LTStrCat(aMsgBuff, "BAD ", nBufferSize);
						break;
					}

					uint16 nChangeID = cParsePacket.Readuint16();

					if(nChangeID & 0x0001) // CLIENTUPDATE_POSITION
						LTStrCat(aMsgBuff, "POS ", nBufferSize);

					if(nChangeID & 0x0002) // CLIENTUPDATE_ROTATION
						LTStrCat(aMsgBuff, "ROT ", nBufferSize);

					if(nChangeID & 0x0004) // CLIENTUPDATE_VELOCITY
						LTStrCat(aMsgBuff, "VEL ", nBufferSize);

					if(nChangeID & 0x0008) // CLIENTUPDATE_AIMING
						LTStrCat(aMsgBuff, "AIM ", nBufferSize);

					if(nChangeID & 0x0010) // CLIENTUPDATE_INPUTALLOWED
						LTStrCat(aMsgBuff, "INP ", nBufferSize);

					if(nChangeID & 0x0020) // CLIENTUPDATE_SCALE
						LTStrCat(aMsgBuff, "SCA ", nBufferSize);

					if(nChangeID & 0x0040) // CLIENTUPDATE_DIMS
						LTStrCat(aMsgBuff, "DIM ", nBufferSize);

					if(nChangeID & 0x0080) // CLIENTUPDATE_FLAGS
						LTStrCat(aMsgBuff, "FL1 ", nBufferSize);

					if(nChangeID & 0x0100) // CLIENTUPDATE_FLAGS2
						LTStrCat(aMsgBuff, "FL2 ", nBufferSize);

					if(nChangeID & 0x0200) // CLIENTUPDATE_MOVEMENTSTATE
						LTStrCat(aMsgBuff, "MST ", nBufferSize);

					if(nChangeID & 0x0400) // CLIENTUPDATE_CTRLFLAGS
						LTStrCat(aMsgBuff, "CTR ", nBufferSize);

					break;
				}

				case 102 : // MID_PLAYER_INFOCHANGE
				{
					LTStrCat(aMsgBuff, "PIC ", nBufferSize);

					if (cParsePacket.TellEnd() < 8)
					{
						LTStrCat(aMsgBuff, "BAD ", nBufferSize);
						break;
					}

					uint8 nChangeID = cParsePacket.Readuint8();

					switch (nChangeID)
					{
						case 1 : //IC_AMMO_ID
							LTStrCat(aMsgBuff, "AMO ", nBufferSize);
							break;
						case 2 : //IC_HEALTH_ID
							LTStrCat(aMsgBuff, "HEA ", nBufferSize);
							break;
						case 3 : //IC_ARMOR_ID
							LTStrCat(aMsgBuff, "ARM ", nBufferSize);
							break;
						case 4 : //IC_WEAPON_ID
							LTStrCat(aMsgBuff, "WEA ", nBufferSize);
							break;
						case 5 : //IC_WEAPON_PICKUP_ID
							LTStrCat(aMsgBuff, "WPI ", nBufferSize);
							break;
						case 6 : //IC_AIRLEVEL_ID
							LTStrCat(aMsgBuff, "AIR ", nBufferSize);
							break;
						case 7 : //IC_ROCKETLOCK_ID
							LTStrCat(aMsgBuff, "ROC ", nBufferSize);
							break;
						case 8 : //IC_OUTOFAMMO_ID
							LTStrCat(aMsgBuff, "OUT ", nBufferSize);
							break;
						case 9 : //IC_OBJECTIVE_ID
							LTStrCat(aMsgBuff, "OBJ ", nBufferSize);
							break;
						case 10 : //IC_MOD_PICKUP_ID
							LTStrCat(aMsgBuff, "MOD ", nBufferSize);
							break;
						case 11 : //IC_EMPTY ??
							LTStrCat(aMsgBuff, "EMP ", nBufferSize);
							break;
						case 12 : //IC_RESET_INVENTORY_ID
							LTStrCat(aMsgBuff, "INV ", nBufferSize);
							break;
						case 13 : //IC_MISSION_TEXT_ID
							LTStrCat(aMsgBuff, "MTX ", nBufferSize);
							break;
						case 14	: //IC_MISSION_FAILED_ID
							LTStrCat(aMsgBuff, "MFA ", nBufferSize);
							break;
						case 15 : //IC_MAX_HEALTH_ID
							LTStrCat(aMsgBuff, "MXH ", nBufferSize);
							break;
						case 16 : //IC_MAX_ARMOR_ID
							LTStrCat(aMsgBuff, "MXA ", nBufferSize);
							break;
						case 17 : //IC_FILL_ALL_CLIPS_ID
							LTStrCat(aMsgBuff, "FAC ", nBufferSize);
							break;
						case 18 : //IC_CANNON_CHARGE_ID
							LTStrCat(aMsgBuff, "CAN ", nBufferSize);
							break;
						case 19 : //IC_BATTERY_CHARGE_ID
							LTStrCat(aMsgBuff, "BAT ", nBufferSize);
							break;
						default :
							LTStrCat(aMsgBuff, "UNK ", nBufferSize);
							break;
					}
					break;
				}

				case 106 : // MID_PLAYER_ORIENTATION
					LTSNPrintF(aTemp, sizeof(aTemp), "PLO |%d|", cParsePacket.TellEnd());
					LTStrCat(aMsgBuff, aTemp, nBufferSize);
					break;

				case 113 : // MID_PLAYER_DAMAGE
					LTSNPrintF(aTemp, sizeof(aTemp), "PLD |%d|", cParsePacket.TellEnd());
					LTStrCat(aMsgBuff, aTemp, nBufferSize);
					break;

				case 190 : //MID_PHYSICS_UPDATE
					LTStrCat(aMsgBuff, "PHU ", nBufferSize);
					break;

				default :
				{
					LTSNPrintF(aTemp, sizeof(aTemp), "%2x |%d| ", (uint32)nMsgID, cParsePacket.TellEnd());
					LTStrCat(aMsgBuff, aTemp, nBufferSize);
					break;
				}
			}
			break;
		}

		case 0xE : //SMSG_PACKETGROUP
			LTStrCat(aMsgBuff, "(GRP) ", nBufferSize);
			break;

//		case 0xF : //SMSG_CHANGEOBJECTFILENAMES
//			LTStrCat(aMsgBuff, "(COF) ", nBufferSize);
//			break;

		case 0x10 : //SMSG_CONSOLEVAR
			LTStrCat(aMsgBuff, "(CV ) ", nBufferSize);
			break;

		case 0x11 : //SMSG_SKYDEF
			LTStrCat(aMsgBuff, "(SKY) ", nBufferSize);
			break;

		case 0x12 : //SMSG_INSTANTSPECIALEFFECT
			LTStrCat(aMsgBuff, "(ISE) ", nBufferSize);
			break;

		case 0x13 : //SMSG_PORTALFLAGS
			LTStrCat(aMsgBuff, "(PF ) ", nBufferSize);
			break;

		case 0x15 : //SMSG_PRELOADLIST
			LTStrCat(aMsgBuff, "(PLL) ", nBufferSize);
			break;

		case 0x17 : //SMSG_THREADLOAD
			LTStrCat(aMsgBuff, "(THL) ", nBufferSize);
			break;

		case 0x18 : //SMSG_UNLOAD
			LTStrCat(aMsgBuff, "(UL ) ", nBufferSize);
			break;

		case 0x19 : //SMSG_LMANIMINFO
			LTStrCat(aMsgBuff, "(LMA) ", nBufferSize);
			break;

		case 0x1A : //SMSG_GLOBALLIGHT
			LTStrCat(aMsgBuff, "(GL ) ", nBufferSize);
			break;

		case 0x32 : //STC_FILEDESC
			LTStrCat(aMsgBuff, "(FD ) ", nBufferSize);
			break;

		case 0x33 : //STC_STARTTRANSFER
			LTStrCat(aMsgBuff, "(ST ) ", nBufferSize);
			break;

		case 0x34 : //STC_CANCELFILETRANSFER
			LTStrCat(aMsgBuff, "(CFT) ", nBufferSize);
			break;

		case 0x35 : //STC_FILEBLOCK
			LTStrCat(aMsgBuff, "(FB ) ", nBufferSize);
			break;

		case 0x36 : //CTS_FILESTATUS
			LTStrCat(aMsgBuff, "(FS ) ", nBufferSize);
			break;

		case 0x38 : //CTS_GOTYOSHIT
			LTStrCat(aMsgBuff, "(GYS) ", nBufferSize);
			break;

		default :
			LTSNPrintF(aTemp, sizeof(aTemp), "(UNK) |%d, %d|", nPacketID, cParsePacket.TellEnd());
			LTStrCat(aMsgBuff, aTemp, nBufferSize);
			break;
	}
}
Beispiel #13
0
bool Protocol79::GameworldLogin () {
    // this is valid for 7.9!
    // 7.7 has a bit different order of stuff! check out old outcast's sources
    NetworkMessage nm;

    SetProtocolStatus("Preparing to transfer logon data...");
    connectiontype = GAMEWORLD;

    nm.AddU8(0x0A); // protocol id

    // in 7.72 onwards move this BEFORE the keys and BEFORE the encryption
    nm.AddU16(0x02); // client OS
    nm.AddU16(protocolversion);

    SetProtocolStatus("RSA encryption...");
    nm.RSABegin();

    //key[3] = 92;
    // encryption keys
    for (int i = 0 ; i < 4 ; i++) {
        nm.AddU32(key[i]);
        //printf("KEY %d - %d\n", i, key[i]);
    }


    // are we a gamemaster
    nm.AddChar(0);

    // account number and password
    nm.AddU32(atol(this->username.c_str())); // this does NOT exist before 7.4
    nm.AddString(this->charlist[this->charlistselected]->charactername);
    nm.AddString(this->password);



    nm.RSAEncrypt();

    SetProtocolStatus("Transmitting logon data...");

    if (!nm.Dump(s)) {
        this->errormsg = "Could not write to socket.\nPossible it's a premature disconnect.\n\nCheck you typed in the correct protocol!";
        return false;
    }


//    SetStance(DEFENSIVE, STAND);

    SetProtocolStatus("Waiting for response...");
    //nm.Clean();
    NetworkMessage nm2;
    //nm.FillFromSocket(s);
    if (!nm2.FillFromSocket(s )) {
        this->errormsg = "Could not read from socket.\nPossibly it's a premature disconnect.\n\nCheck you typed in the correct protocol!";
        return false;
    }
    nm2.XTEADecrypt(key);
    logonsuccessful = true;
    while ((signed int)(nm2.GetSize())>0 && ParsePacket(&nm2));
    if ((signed int)(nm2.GetSize())!=0) printf("++++++++++++++++++++DIDNT EMPTY UP THE NETWORKMESSAGE!++++++++++++++++++\n");

    if (logonsuccessful) active = true;

    return logonsuccessful;
}
void Sabertooth::StopAll(){
	ParsePacket(127, 127);
}
Beispiel #15
0
int main(void)
{ 
  // don;t want to fire on power up !
  P2SEL = 0;
  P2SEL2 = 0;
  P3OUT = 0;
  P2OUT = 0;
  P3DIR = 0xff;
  
  //WDTCTL = WDTPW + WDTHOLD;
    WDTCTL = WDT_ARST_250;
   
   // sET UP aclk
   BCSCTL3 |= LFXT1S_2;
   
   // Set all pins to output to stop floating
   P1DIR = 0xC0;
   P2DIR = 0xFF;
   P3DIR = 0xFF;

   // device running at 16MHz 
   BCSCTL1= CALBC1_16MHZ;
   DCOCTL = CALDCO_16MHZ;    
   
   Green();

   bRGBValues[0] = 97;
   bRGBValues[1] = 97;
   bRGBValues[2] = 97;
   bRGBValues[3] = 97;
   bRGBValues[4] = 97;
   bRGBValues[5] = 97;
   
   LoadConfig();
   
   
   DoSWPWM(); 
   
   initXBus();
   
   _EINT();
  
   int i = 0;
  while (1)
  {
    if (NewPacket())
    {
      bLastMessage = 0;
      ParsePacket();
      bRGBValues[0] = RCScale(Channel((RGB1_RED)));
      bRGBValues[1] = RCScale(Channel((RGB1_GREEN)));
      bRGBValues[2] = RCScale(Channel((RGB1_BLUE)));
      bRGBValues[3] = RCScale(Channel((RGB2_RED)));
      bRGBValues[4] = RCScale(Channel((RGB2_GREEN)));
      bRGBValues[5] = RCScale(Channel((RGB2_BLUE)));
      
      BlackoutCheck();
     
      // check for pyro fire
      P2OUT &= ~BIT5;
      P2OUT &= ~BIT4;
      if (Channel(PYRO1_FIRE) == 0xDE)
      {
        P2OUT |= BIT5;
      }
      if (Channel(PYRO2_FIRE) == 0xDE)
      {
        P2OUT |= BIT4;
      }

      if (i)
      {
        Red();
        i = 0;
      }
      else
      {
        Green();
        i = 1;
      }
    }  
    
    
    if (bLastMessage > 5000)
    {
      bRGBValues[0] = 0xff;
      bRGBValues[1] = 0;
      bRGBValues[2] = 0xff;
      bRGBValues[3] = 0xff;
      bRGBValues[4] = 0;
      bRGBValues[5] = 0xff;
      bLastMessage = 0;
      Red();
    }
    
      WDTCTL = WDT_ARST_250;
  }
}
Beispiel #16
0
CTsPacket::CTsPacket(const BYTE *pHexData)
	: CMediaData(pHexData, TS_PACKETSIZE)
{
	// バイナリデータからパケットを生成する
	ParsePacket();
}