Пример #1
0
 public virtual void OnSend(IClientPeer p)
 {
     #if DEBUG
     Console.WriteLine("S -> C, Length {0}:", m_Buffer.Length);
     DumpArray(Console.Out, m_Buffer);
     #endif
 }
        public ClientPeerWrapper(IClientPeer peer, int peerId)
        {
            Peer   = peer;
            PeerId = peerId;

            SubscribeToPeerDisconnectionNotifier();
        }
Пример #3
0
 public virtual void OnSend(IClientPeer p)
 {
     #if DEBUG
     Console.WriteLine("S -> C, Length {0}:", m_Buffer.Length);
     DumpArray(Console.Out, m_Buffer);
     #endif
 }
Пример #4
0
        public void UOExtPacket(IClientPeer peer, byte header, byte[] buffer, int offset, short length)
        {
            MemoryStream ms = new MemoryStream(buffer, offset, length);
            BinaryReader br = new BinaryReader(ms);

            byte sequence = br.ReadByte();

            switch (sequence)
            {
            case (0x00):
                byte   version     = br.ReadByte();
                byte[] uoextmd5    = br.ReadBytes(16);
                byte[] uoextguimd5 = br.ReadBytes(16);
                if (version != 0)
                {
                    peer.Close();
                }
                else
                {
                    if (!ByteArrayCompare(uoextmd5, Dll.UOExt.MD5))
                    {
                        peer.Send(new Handshake(0x01));
                        peer.Send(Dll.UOExt.SimpleHeader);
                        foreach (DllContent dc in Dll.UOExt.Content)
                        {
                            peer.Send(dc);
                        }
                        return;
                    }
                    else if (!ByteArrayCompare(uoextguimd5, Dll.UOExtGUI.MD5))
                    {
                        peer.Send(new Handshake(0x02));
                        peer.Send(Dll.UOExtGUI.SimpleHeader);
                        foreach (DllContent dc in Dll.UOExtGUI.Content)
                        {
                            peer.Send(dc);
                        }
                    }
                    else
                    {
                        peer.Send(new Handshake(0x00));
                    }
                    peer.Send(m_libraryList);
                    peer.Send(m_pluginsList);
                }
                break;

            case (0x03):
                for (short i = 0; i < Dll.Dlls.Length; i++)
                {
                    peer.Send(Dll.Dlls[i].Header);
                    foreach (DllContent dc in Dll.Dlls[i].Content)
                    {
                        peer.Send(dc);
                    }
                }
                peer.Send(m_initComplete);
                break;
            }
        }
Пример #5
0
        public bool HandleMessage(IMessage message, IServerPeer peer)
        {
            // Got a response back from the LoginUserPass - might be successful, might not.
            if (message.Parameters.ContainsKey(_serverConfiguration.PeerIdCode))
            {
                Log.DebugFormat("Looking for Peer Id {0}", new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));
                IClientPeer clientPeer = _connectionCollection.GetPeers <IClientPeer>().FirstOrDefault(p => p.PeerId == new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));
                if (clientPeer != null)
                {
                    Log.DebugFormat("Found Peer");

                    var response = message as Response;
                    // copy our response to a return response
                    Response returnResponse = new Response(Code, SubCode, message.Parameters);
                    // remove any unnecessary codes from the returning packet
                    _clientCodeRemover.RemoveCodes(returnResponse);

                    if (response.ReturnCode == (short)ReturnCode.OK)
                    {
                        // Good response, get the client data and look for the userId to set it for the future.
                        clientPeer.ClientData <CharacterData>().UserId = (int)response.Parameters[(byte)MessageParameterCode.UserId];
                    }
                    // make one call to send the message back - One "exit point" for the message.
                    clientPeer.SendMessage(response);
                }
            }
            return(true);
        }
 public void SendUpdate(IClientPeer instance)
 {
     if (instance != null)
     {
         instance.SendMessage(new Event(20, 1, new Dictionary <byte, object>()));
     }
 }
Пример #7
0
        public void Send(IClientPeer p) 
        {
            m_Writer.Flush();
            p.Send(m_Buffer);
            this.OnSend(p);

        }
Пример #8
0
        public void UOExtPacket(IClientPeer peer, byte header, byte[] buffer, int offset, short length)
        {
            MemoryStream ms = new MemoryStream(buffer, offset, length);
            BinaryReader br = new BinaryReader(ms);

            byte sequence = br.ReadByte();

            switch (sequence)
            {
                case (0x00):
                    byte version = br.ReadByte();
                    byte[] uoextmd5 = br.ReadBytes(16);
                    byte[] uoextguimd5 = br.ReadBytes(16);
                    if (version != 0)
                    {
                        peer.Close();
                    }
                    else
                    {

                        if (!ByteArrayCompare(uoextmd5, Dll.UOExt.MD5))
                        {
                            peer.Send(new Handshake(0x01));
                            peer.Send(Dll.UOExt.SimpleHeader);
                            foreach (DllContent dc in Dll.UOExt.Content)
                            {
                                peer.Send(dc);
                            }
                            return;
                        }
                        else if (!ByteArrayCompare(uoextguimd5, Dll.UOExtGUI.MD5))
                        {
                            peer.Send(new Handshake(0x02));
                            peer.Send(Dll.UOExtGUI.SimpleHeader);
                            foreach (DllContent dc in Dll.UOExtGUI.Content)
                            {
                                peer.Send(dc);
                            }
                        }
                        else
                        {
                            peer.Send(new Handshake(0x00));
                        }
                        peer.Send(m_libraryList);
                        peer.Send(m_pluginsList);
                    }
                    break;
                case (0x03):
                    for (short i = 0; i < Dll.Dlls.Length; i++)
                    {
                        peer.Send(Dll.Dlls[i].Header);
                        foreach (DllContent dc in Dll.Dlls[i].Content)
                        {
                            peer.Send(dc);
                        }
                    }
                    peer.Send(m_initComplete);
                    break;
            }
        }
Пример #9
0
 public void SendUpdate(IClientPeer instance)
 {
     if (instance != null)
     {
         Log.DebugFormat("Send message to peer");
         instance.SendMessage(new Event(20, 1, new Dictionary <byte, object>()));
     }
 }
Пример #10
0
 public override void DisconnectPeer(IClientPeer peer)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine($"Client Peer {peer.ClientData<UserData>().Id} disconnected from {GetType().Name}");
     Console.ResetColor();
     ConnectionCollection.Disconnect(peer);
     peer.Client.MessageReceived -= OnOperationRequest;
 }
Пример #11
0
 public override void ConnectPeer(IClientPeer peer)
 {
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine($"Client Peer connected to {GetType().Name}");
     Console.ResetColor();
     ConnectionCollection.Connect(peer);
     peer.Server = this;
     peer.Client.MessageReceived += OnOperationRequest;
 }
        protected void WrapClientPeer(IClientPeer clientPeer, IPeerLogicBase peerLogic)
        {
            var idGenerator = ServerComponents.GetComponent <IIdGenerator>().AssertNotNull();
            var peerId      = idGenerator.GenerateId();

            var clientPeerWrapper = new ClientPeerWrapper(clientPeer, peerId);

            clientPeerWrapper.SetPeerLogic(peerLogic);

            peerContainer.AddPeerLogic(clientPeerWrapper);
        }
Пример #13
0
 public void ProcessBuffer(IClientPeer peer, byte header, byte[] buffer, int offset, short length)
 {
     short packetSize = GetPacketLength(header);
     if ((packetSize != length)&&(packetSize != 0))
     {
         // Big error here!
     }
     OnPacketRecive handler = GetPacketHandler(header);
     if (handler != null)
         handler(peer, header, buffer, offset, length);
 }
Пример #14
0
        public bool AddClientPeer(ServerType type, IClientPeer clientPeer)
        {
            if (PeerList.ContainsKey(type))
            {
                return(false);
            }
            else
            {
                PeerList.Add(type, clientPeer);

                return(true);;
            }
        }
Пример #15
0
        public void ProcessBuffer(IClientPeer peer, byte header, byte[] buffer, int offset, short length)
        {
            short packetSize = GetPacketLength(header);

            if ((packetSize != length) && (packetSize != 0))
            {
                // Big error here!
            }
            OnPacketRecive handler = GetPacketHandler(header);

            if (handler != null)
            {
                handler(peer, header, buffer, offset, length);
            }
        }
        public override void OnConnected(IClientPeer clientPeer)
        {
            base.OnConnected(clientPeer);

            var tcpPort = (int)Config.Global.ConnectionInfo.TcpPort;

            if (clientPeer.ConnectionInformation.Port == tcpPort)
            {
                WrapClientPeer(clientPeer, new UnauthenticatedServerPeerLogic <InboundServerPeerLogic>());
            }
            else
            {
                WrapClientPeer(clientPeer, new UnauthorizedClientPeerLogic <AuthorizedClientPeerLogic>());
            }
        }
        public override void OnConnected(IClientPeer clientPeer)
        {
            base.OnConnected(clientPeer);

            LogUtils.Assert(Config.Global.ConnectionInfo, MessageBuilder.Trace("Could not find an connection info for the server."));

            var udpPort = (int)Config.Global.ConnectionInfo.UdpPort;
            var tcpPort = (int)Config.Global.ConnectionInfo.TcpPort;

            var clientConnectionInfo = clientPeer.ConnectionInformation;

            if (clientConnectionInfo.Port == udpPort)
            {
                WrapClientPeer(clientPeer, new ClientPeerLogic());
            }
            else if (clientConnectionInfo.Port == tcpPort)
            {
                WrapClientPeer(clientPeer, new ServerPeerLogic());
            }
            else
            {
                LogUtils.Log($"No handler found for peer: {clientConnectionInfo.Ip}:{clientConnectionInfo.Port}");
            }
        }
Пример #18
0
 public abstract void DisconnectPeer(IClientPeer peer);
Пример #19
0
        public override void OnConnected(IClientPeer clientPeer)
        {
            base.OnConnected(clientPeer);

            WrapClientPeer(clientPeer, new UnauthorizedClientPeerLogic <CharacterSelectionPeerLogic>());
        }
        public override void OnConnected(IClientPeer clientPeer)
        {
            base.OnConnected(clientPeer);

            WrapClientPeer(clientPeer, new ClientPeerLogic());
        }
Пример #21
0
 public bool HandleMessage(IMessage message, ISubServer subServer, IClientPeer peer)
 {
     this.peer = peer;
     return(HandleMessage(message, subServer));
 }
Пример #22
0
 public void Send(IClientPeer p)
 {
     m_Writer.Flush();
     p.Send(m_Buffer);
     this.OnSend(p);
 }
        public override void OnConnected(IClientPeer clientPeer)
        {
            base.OnConnected(clientPeer);

            WrapClientPeer(clientPeer, new UnauthenticatedServerPeerLogic <InboundServerPeerLogic>());
        }
 public virtual void OnConnected(IClientPeer clientPeer)
 {
     LogUtils.Log($"A new peer has been connected -> {clientPeer.ConnectionInformation.Ip}:{clientPeer.ConnectionInformation.Port}");
 }
Пример #25
0
 public ClientPeerProvider(int peerId, IClientPeer peer)
 {
     PeerId = peerId;
     Peer   = peer.AssertNotNull();
 }