Beispiel #1
0
            private bool HandleData(byte[] data)
            {
                int packetLen = 0;

                ReceivePacket.SetBytes(data);

                if (ExitHandleData(ref packetLen))
                {
                    return(true);
                }

                while (packetLen > 0 && packetLen <= ReceivePacket.UnreadLength())
                {
                    byte[] bytes = ReceivePacket.ReadBytes(packetLen);
                    ThreadManager.ExecuteOnMainThread(() =>
                    {
                        using (Packet packet = new Packet(bytes))
                        {
                            try
                            {
                                int packetId = packet.ReadInt();
                                Server.PacketHandlerDictionary[packetId](ID, packet);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine($"\n\tError in TCP HandlePacket of GameServer Client: {ID}...\n{exception}");
                                //Server.ClientDictionary[ID].Disconnect();
                                //Instead of disconnecting straight away, make sure packets are being received from this player,
                                //  If still receiving packets, then don't disconnect
                                //  Else, disconnect player
                            }
                        }
                    });
                    packetLen = 0;

                    if (ExitHandleData(ref packetLen))
                    {
                        return(true);
                    }
                }
                if (packetLen < 2)
                {
                    return(true);
                }

                return(false);
            }
Beispiel #2
0
            private bool HandleData(byte[] data)
            {
                int packetLen = 0;

                ReceivePacket.SetBytes(data);

                if (ExitHandleData(ref packetLen))
                {
                    return(true);
                }

                while (packetLen > 0 && packetLen <= ReceivePacket.UnreadLength())
                {
                    byte[] bytes = ReceivePacket.ReadBytes(packetLen);
                    ThreadManager.ExecuteOnMainThread(() =>
                    {
                        using (Packet packet = new Packet(bytes))
                        {
                            int packetId = packet.ReadInt();
                            Server.PacketHandlerDictionary[packetId](ID, packet);
                        }
                    });
                    packetLen = 0;

                    if (ExitHandleData(ref packetLen))
                    {
                        return(true);
                    }
                }
                if (packetLen < 2)
                {
                    return(true);
                }

                return(false);
            }