Exemplo n.º 1
0
        private void HandleClient(object cObj)
        {
            TcpClient Client = (TcpClient)cObj;

            Tmp.Entry Entry = new Tmp.Entry();
            GlobalVar.nStream = Client.GetStream();

            byte[] Header = new byte[8];
            Entry.IP = Client.Client.RemoteEndPoint.ToString().Split(':')[0];
            GlobalFunc.Write("Client [{0}] - Connected", Entry.IP);

            using (PoorManStream pmStream = new PoorManStream(GlobalVar.nStream)) {
                using (EndianIO MainIO = new EndianIO(Header, EndianStyle.BigEndian)) {
                    if (GlobalVar.nStream.Read(Header, 0, 8) != 8)
                    {
                        GlobalFunc.WriteError(ConsoleColor.Red, "[SERVER]", "Header recieved unexpected size!"); Client.Close();
                    }
                    uint   Command    = MainIO.Reader.ReadUInt32();
                    int    PacketSize = MainIO.Reader.ReadInt32();
                    byte[] Buffer     = new byte[PacketSize];
                    using (EndianIO WriterIO = new EndianIO(pmStream, EndianStyle.BigEndian)) {
                        using (EndianIO ReaderIO = new EndianIO(Buffer, EndianStyle.BigEndian)
                        {
                            Writer = new EndianWriter(pmStream, EndianStyle.BigEndian)
                        }) {
                            if (pmStream.Read(Buffer, 0, PacketSize) != PacketSize)
                            {
                                GlobalFunc.WriteError(ConsoleColor.Red, "[SERVER]", "Packet recieved unexpected size!"); Client.Close();
                            }

                            switch (Command)
                            {
                            case (uint)cmdCode.GET_SESSION: SESSION.Get(ref Entry, WriterIO, ReaderIO); break;

                            case (uint)cmdCode.GET_STATUS: STATUS.Get(ref Entry, WriterIO, ReaderIO); break;

                            case (uint)cmdCode.GET_CHAL_RESPONSE: break;

                            case (uint)cmdCode.UPDATE_PRESENCE: PRESENCE.Update(ref Entry, WriterIO, ReaderIO); break;

                            case (uint)cmdCode.GET_XOSC: break;

                            case (uint)cmdCode.GET_INFO: break;

                            case (uint)cmdCode.SND_SPOOFY: break;

                            case (uint)cmdCode.GET_MESSAGE: break;

                            case (uint)cmdCode.GET_PATCHES: break;

                            case (uint)cmdCode.GET_GUIDE_INFO: break;

                            default: break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static bool CacheEntry(Tmp.Entry Client)
 {
     if (!Exists(Client))
     {
         Tmp.CachedEntry.Add(Client);
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public static bool CacheModify(Tmp.Entry Client)
 {
     if (Exists(Client))
     {
         int Found = Tmp.CachedEntry.FindIndex(i => i.CPUKey == Client.CPUKey);
         Tmp.CachedEntry[Found] = Client;
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public static bool Exists(Tmp.Entry Client)
 {
     return(Tmp.CachedEntry.Exists(i => i.CPUKey == Client.CPUKey));
 }