Пример #1
0
        private void ProcessReceiveBuffer(byte[] buffer)
        {
            if (buffer == null || buffer.Length < PortalPacket.MinSize)
            {
                return;
            }

            var pid = BitConverter.ToUInt16(buffer, 0);

            PortalPacketHandler handler;

            lock (((ICollection)Handlers).SyncRoot)
            {
                if (!Handlers.TryGetValue(pid, out handler) || handler == null)
                {
                    if (_DisplayRecvOutput)
                    {
                        ToConsole("Recv: Missing Handler for {0}", pid);
                    }

                    return;
                }
            }

            if (handler.Context == PortalContext.Disabled)
            {
                if (_DisplayRecvOutput)
                {
                    ToConsole("Recv: Ignoring Packet {0}", pid);
                }

                return;
            }

            if (handler.Context != PortalContext.Any &&
                ((handler.Context == PortalContext.Server && !IsRemoteClient) ||
                 (handler.Context == PortalContext.Client && !IsLocalClient)))
            {
                if (_DisplayRecvOutput)
                {
                    ToConsole("Recv: Out Of Context Packet {0} requires {1}", pid, handler.Context);
                }

                return;
            }

            if (_DisplayRecvOutput)
            {
                ToConsole("Recv: Received Packet {0} at {1} bytes", pid, buffer.Length);
            }

            using (var p = new PortalPacketReader(buffer))
            {
                handler.OnReceive(this, p);
            }
        }
Пример #2
0
        private static void OnHandshakeRequest(PortalClient client, PortalPacketReader p)
        {
            if (client.IsAuthed)
            {
                client.Send(PortalPackets.HandshakeResponse.Accepted);
                return;
            }

            var key = p.ReadBytes(20);

            client.IsAuthed = PortalAuthentication.Key.SequenceEqual(key);

            var r = client.IsAuthed ? PortalPackets.HandshakeResponse.Accepted : PortalPackets.HandshakeResponse.Rejected;

            client.Send(r);
        }
Пример #3
0
        private void ProcessReceiveBuffer(byte[] buffer)
        {
            if (buffer == null || buffer.Length < PortalPacket.MinSize)
            {
                return;
            }

            var pid = buffer[0];

            PortalPacketHandler handler;

            lock (((ICollection)Handlers).SyncRoot)
            {
                if (!Handlers.TryGetValue(pid, out handler) || handler == null)
                {
                    ToConsole("Recv: Missing Handler for {0}", pid);
                    return;
                }
            }

            if (handler.Length > 0 && buffer.Length != handler.Length)
            {
                ToConsole("Recv: Size Not Equal for {0} at {1}/{2} bytes", pid, buffer.Length, handler.Length);
                return;
            }

            if (handler.Context == PortalContext.Disabled)
            {
                ToConsole("Recv: Ignoring Packet {0}", pid);
                return;
            }

            if (handler.Context != PortalContext.Any && handler.Context != Portal.Context)
            {
                ToConsole("Recv: Out Of Context Packet {0} requires {1}", pid, handler.Context);
                return;
            }

            ToConsole("Recv: Received Packet {0} at {1} bytes", pid, buffer.Length);

            using (var p = new PortalPacketReader(buffer))
            {
                handler.OnReceive(this, p);
            }
        }
Пример #4
0
        private static void OnHandshakeRequest(PortalClient client, PortalPacketReader p)
        {
            if (client.IsAuthed)
            {
                client.Send(PortalPackets.HandshakeResponse.Accepted);
                return;
            }

            var key = p.ReadBytes(20);

            client.IsAuthed = PortalAuthentication.Verify(key);

            if (client.IsAuthed && Portal.UniqueIDs && Portal.Transport is PortalServer &&
                ((PortalServer)Portal.Transport).Clients.Any(c => c != client && c.IsIdentified && c.ServerID == p.ServerID))
            {
                client.IsAuthed = false;
            }

            var r = client.IsAuthed             //
                                ? PortalPackets.HandshakeResponse.Accepted
                                : PortalPackets.HandshakeResponse.Rejected;

            client.Send(r);
        }
Пример #5
0
 private static void OnDisconnectNotify(PortalClient client, PortalPacketReader p)
 {
     client.Dispose();
 }
Пример #6
0
 private static void OnPingResponse(PortalClient client, PortalPacketReader p)
 {
     p.ReadToEnd();             // random bytes
 }
Пример #7
0
        private static void OnPingRequest(PortalClient client, PortalPacketReader p)
        {
            p.ReadToEnd();             // random bytes

            client.Send(PortalPackets.PingResponse.Instance);
        }
Пример #8
0
 private static void OnHandshakeResponse(PortalClient client, PortalPacketReader p)
 {
     client.IsAuthed = p.ReadBoolean();
 }
Пример #9
0
        private static void OnPingRequest(PortalClient client, PortalPacketReader p)
        {
            //p.ReadToEnd(); // random bytes

            client.Ping(true);
        }