Exemplo n.º 1
0
        internal bool ProcessGameData(string data, out string resp)
        {
            resp = "OK";
            string[] chunk = GameDataSplitter.Split(data);
            if (chunk.Length > 1)
            {
                string command = chunk[chunk.Length - 1];
                if (command == "READ_KEY")
                {
                    ushort playerid = ushort.Parse(chunk[0]);
                    GDP    gdp      = MakePacket(GDPCommand.READ_KEY, playerid, "");
                    AddPacket(playerid, gdp);
                    gdp = WaitForResponse(playerid);
                    if (gdp.Command == 14)
                    {
                        resp = Encoding.UTF8.GetString(gdp.Data);
                    }
                    else
                    {
                        resp = "000";
                    }
                    return(true);
                }


                else if (command == "STREAM_P")
                {
                    ushort playerid = ushort.Parse(chunk[0]);

                    GDP gdp = MakePacket(GDPCommand.PLAY_STREAM, playerid, chunk[1] + ";" + Streamer.GetVidTime(ushort.Parse(chunk[1])).ToString());
                    AddPacket(playerid, gdp);

                    return(true);
                }
                else if (command == "STREAM_B")
                {
                    ushort playerid = ushort.Parse(chunk[0]);
                    // Start the stream from server
                    Streamer.StreamVID(ushort.Parse(chunk[0]));
                    return(true);
                }
                else if (command == "LOGIN")
                {
                    ushort playerid = ushort.Parse(chunk[0]);
                    string username = chunk[1];
                    string AT       = GenerateAccessToken();
                    AddToken(playerid, AT);
                    AddPlayer(playerid, username);
                    CreatePacketStore(playerid);
                    return(true);
                }
                else if (command == "LOGOUT")
                {
                    ushort playerid = ushort.Parse(chunk[0]);
                    if (PlayerTable.ContainsKey(playerid))
                    {
                        PlayerTable.Remove(playerid);
                    }

                    if (AccessTok.ContainsKey(playerid))
                    {
                        AccessTok.Remove(playerid);
                    }

                    if (PacketStore.ContainsKey(playerid))
                    {
                        PacketStore.Remove(playerid);
                    }
                    return(true);
                }
                else if (command == "SAY_TTS")
                {
                    ushort playerid = ushort.Parse(chunk[0]);

                    GDP gdp = MakePacket(GDPCommand.PLAY_VOICE, playerid, chunk[1]);
                    AddPacket(playerid, gdp);
                    return(true);
                }
                else if (command == "STOP_TTS")
                {
                    ushort playerid = ushort.Parse(chunk[0]);

                    GDP gdp = MakePacket(GDPCommand.STOP_VOICE, playerid, "");
                    AddPacket(playerid, gdp);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }