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);
        }
 private static void OnPingResponse(PortalClient client, PortalPacketReader p)
 {
     p.ReadToEnd(); // random bytes
 }
        private static void OnPingRequest(PortalClient client, PortalPacketReader p)
        {
            p.ReadToEnd(); // random bytes

            client.Send(PortalPackets.PingResponse.Instance);
        }
 private static void OnHandshakeResponse(PortalClient client, PortalPacketReader p)
 {
     client.IsAuthed = p.ReadBoolean();
 }
 private static void OnDisconnectNotify(PortalClient client, PortalPacketReader p)
 {
     client.Dispose();
 }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
            }
        }