예제 #1
0
 void generatePackets()
 {
     packet pck = new packet(m_buffer);
     switch (pck.getPacketType())
     {
         case PACKET_TYPE.S_ACCEPT:
             if (m_state == state.WAIT_FOR_ACCEPT)
             {
                 m_buffer.RemoveAt(0);
                 //print("got accept!");
                 m_state = state.ONLINE;
                 sendGetOnlineSockets();
             }
             else
             {
                 print("invalid packet! recieved accept at the wrong time!");
                 callDisconnect();
             }
             break;
         case PACKET_TYPE.S_SEND_ONLINE_CLIENTS:
             if (m_state == state.ONLINE)
             {
                 parseOnlineClientsPacket(pck);
                 m_buffer.RemoveRange(0, pck.getPacketSize());
             }
             else
             {
                 print("invalid state! is not online! but got S_SEND_ONLINE_CLIENTS");
                 callDisconnect();
             }
             break;
         case PACKET_TYPE.S_SOCKET_UPDATE:
             if (m_state == state.ONLINE)
             {
                 //print("got S_SOCK_UPDATE");
                 parseSocketUpdate(pck);
                 m_buffer.RemoveRange(0, 4);
             }
             else
             {
                 print("invalid state! is not online! but got S_SOCKET_UPDATE");
                 callDisconnect();
             }
             break;
         case PACKET_TYPE.S_SOCKET_POWER_UPDATE:
             if (m_state != state.ONLINE)
             {
                 print("invalid state! is not online! but got S_SOCKET_POWER_INFO");
                 callDisconnect();
                 break;
             }
             parsePowerUpdate(pck);
             m_buffer.RemoveRange(0, 7);
             break;
         case PACKET_TYPE.S_SOCKET_POWER_INFO:
             if (m_state != state.ONLINE)
             {
                 print("invalid state! is not online! but got S_SOCKET_POWER_INFO");
                 callDisconnect();
                 break;
             }
             parsePowerInfo(pck);
             m_buffer.RemoveRange(0, 20);
             break;
         case PACKET_TYPE.SC_PING:
             if (m_state != state.ONLINE)
             {
                 print("invalid state! is not online! but got SC_PING");
                 callDisconnect();
                 break;
             }
             parsePingPacket(pck);
             m_buffer.RemoveRange(0, pck.getPacketSize());
             break;
         case PACKET_TYPE.SC_SEND_XML:
             if (m_state != state.ONLINE)
             {
                 print("invalid state! is not online! but got SC_PING");
                 callDisconnect();
                 break;
             }
             parseSendXML(pck);
             m_buffer.RemoveRange(0, pck.getPacketSize());
             break;
         case PACKET_TYPE.SC_SEND_PICTURE:
             if (m_state != state.ONLINE)
             {
                 print("invalid state! is not online! but got SC_PING");
                 callDisconnect();
                 break;
             }
             parseSendPicture(pck);
             m_buffer.RemoveRange(0, pck.getPacketSize());
             break;
         case PACKET_TYPE.ERR_NONE:
         case PACKET_TYPE.ERR_NOT_DONE:
             break;
         default:
             print("unknown packet id :" + pck.getPacketType());
             callDisconnect();
             break;
     }
 }