public static void OnAuthenticationTicketMessage(INetworkClient client, AuthenticationTicketMessage im)
        {
            client.Send(new AuthenticationTicketAcceptedMessage());

            var accountId = client.GetEntity().GetComponent <AccountComponent>().AccountId;

            client.Send(new AccountCapabilitiesMessage(accountId));
        }
Exemple #2
0
 private void VirtueMenu_MouseDoubleClickEvent(AControl control, int x, int y, MouseButton button)
 {
     if (button == MouseButton.Left)
     {
         _client.Send(new GumpMenuSelectPacket(Mobile.Serial, 0x000001CD, 0x00000001, new int[1] {
             Mobile.Serial
         }, null));
     }
 }
Exemple #3
0
 public static void OnIdentificationMessage(INetworkClient client, IdentificationMessage im)
 {
     client.Send(new IdentificationSuccessMessage());
     client.Send(new SelectedServerDataExtendedMessage());
     Task.Run(async() =>
     {
         await Task.Delay(TimeSpan.FromSeconds(1));
         client.Disconnect();
     });
 }
        private void btnSend_Click(object sender, EventArgs e)
        {
            byte[] update_rate = BitConverter.GetBytes(gps_list[selected_index].update_rate);
            byte[] msg         = new byte[2];
            AddMsg(gps_list[selected_index].update_rate.ToString() + " " + gps_list[selected_index].Name);
            switch (gps_list[selected_index].Name)
            {
            case "GGA":
                msg = BitConverter.GetBytes(0);
                break;

            case "GLL":
                msg = BitConverter.GetBytes(1);
                break;

            case "GSA":
                msg = BitConverter.GetBytes(2);
                break;

            case "GSV":
                msg = BitConverter.GetBytes(3);
                break;

            case "RMC":
                msg = BitConverter.GetBytes(4);
                break;

            case "VTG":
                msg = BitConverter.GetBytes(5);
                break;

            case "ZDA":
                msg = BitConverter.GetBytes(6);
                break;

            default:
                break;
            }
            byte[] bytes = new byte[msg.Count() + update_rate.Count() + 2];

            //System.Buffer.BlockCopy(src, src_offset, dest, dest_offset,count)
            System.Buffer.BlockCopy(msg, 0, bytes, 2, msg.Count());
            System.Buffer.BlockCopy(update_rate, 0, bytes, 4, update_rate.Count());
            bytes[0] = svrcmd.GetCmdIndexB("SET_GPS_DATA");
            Packet packet = new Packet(bytes, 0, bytes.Count(), false);

            //AddMsg(bytes.Count().ToString());
            if (m_client.IsConnectionAlive)
            {
                m_client.Send(packet);
            }
        }
Exemple #5
0
        private void SendKeepAlivePacket()
        {
            if (!m_Network.IsConnected)
            {
                StopKeepAlivePackets();
                return;
            }

            m_Network.Send(new ClientPingPacket());
        }
Exemple #6
0
        /// <summary>
        /// Connect to a server!
        /// </summary>
        /// <param name="host">Address of the host. Can be a website or an ip address. IP addresses should be IPv4.</param>
        /// <param name="port">Port of the server on the host.</param>
        /// <returns></returns>
        public bool Connect(string host, int port)
        {
            Status = LoginClientStatus.LoginServer_Connecting;
            bool success = m_Network.Connect(host, port);

            if (success)
            {
                Status = LoginClientStatus.LoginServer_WaitingForLogin;

                var clientVersion = Settings.UltimaOnline.ClientVersion;

                if (clientVersion.Length != 4)
                {
                    Tracer.Warn("Cannot send seed packet: Version array is incorrectly sized.");
                }
                else
                {
                    m_Network.Send(new SeedPacket(1, clientVersion));
                }
            }
            else
            {
                Status = LoginClientStatus.Error_CannotConnectToServer;
            }
            return(success);
        }
 void Send(GameMessage msg)
 {
     if (client.Connected)
     {
         client.Send(msg);
     }
 }
Exemple #8
0
        private void okButton_MouseClickEvent(AControl control, int x, int y, MouseButton button)
        {
            if (button != MouseButton.Left)
            {
                return;
            }

            List <Tuple <int, short> > itemsToBuy = new List <Tuple <int, short> >();

            for (int i = 0; i < m_Items.Length; i++)
            {
                if (m_Items[i].AmountToSell > 0)
                {
                    itemsToBuy.Add(new Tuple <int, short>(m_Items[i].Serial, (short)m_Items[i].AmountToSell));
                }
            }

            if (itemsToBuy.Count == 0)
            {
                return;
            }

            INetworkClient network = ServiceRegistry.GetService <INetworkClient>();

            network.Send(new SellItemsPacket(m_VendorSerial, itemsToBuy.ToArray()));
            this.Dispose();
        }
Exemple #9
0
 // ============================================================================================================
 // Connection and Disconnect
 // ============================================================================================================
 public bool Connect(string host, int port, string account, SecureString password)
 {
     Disconnect();
     if (_network.Connect(host, port))
     {
         _userName = account;
         _password = password;
         _network.Send(new SeedPacket(0x1337BEEF, UltimaGameSettings.UltimaOnline.PatchVersion));
         Login(_userName, _password);
         return(true);
     }
     return(false);
 }
        public static void OnCharacterSelection(INetworkClient client, CharacterSelectionMessage csm)
        {
            var loginEntity     = client.GetEntity();
            var characterEntity = EntityManager.Instance.Get((uint)csm.CharacterId);

            characterEntity.AddComponent <AccountComponent>();
            characterEntity.AddComponent <NetworkComponent>();
            characterEntity.AddComponent <MapComponent>();
            characterEntity.AddComponent <GameContextComponent>();
            characterEntity.Account().AccountId = loginEntity.Account().AccountId;
            characterEntity.Network().Client    = loginEntity.Network().Client;
            characterEntity.RefId = loginEntity.RefId;
            EntityManager.Instance.Delete(loginEntity.Id);

            client.Send(new CharacterSelectedSuccessMessage(characterEntity));
            client.Send(new CharacterLoadingCompleteMessage());
            characterEntity.Notify(new ClientEnteringGameEventArgs());
        }
Exemple #11
0
        public override void OnButtonClick(int buttonID)
        {
            switch ((Buttons)buttonID)
            {
            case Buttons.Map:
                MiniMapGump.Toggle();
                break;

            case Buttons.Paperdoll:
                var player = (Mobile)WorldModel.Entities.GetPlayerEntity();
                if (UserInterface.GetControl <PaperDollGump>(player.Serial) == null)
                {
                    _client.Send(new DoubleClickPacket(player.Serial | Serial.ProtectedAction));     // additional flag keeps us from being dismounted.
                }
                else
                {
                    UserInterface.RemoveControl <PaperDollGump>(player.Serial);
                }
                break;

            case Buttons.Inventory:
                // opens the player's backpack.
                var mobile   = WorldModel.Entities.GetPlayerEntity();
                var backpack = mobile.Backpack;
                _world.Interaction.DoubleClick(backpack);
                break;

            case Buttons.Journal:
                if (UserInterface.GetControl <JournalGump>() == null)
                {
                    UserInterface.AddControl(new JournalGump(), 80, 80);
                }
                else
                {
                    UserInterface.RemoveControl <JournalGump>();
                }
                break;

            case Buttons.Chat:
                break;

            case Buttons.Help:
                break;

            case Buttons.Question:
                if (UserInterface.GetControl <DebugGump>() == null)
                {
                    UserInterface.AddControl(new DebugGump(), 50, 50);
                }
                else
                {
                    UserInterface.RemoveControl <DebugGump>();
                }
                break;
            }
        }
        public Task HandleAsync(INetworkClient client, ServerPacket packet)
        {
            this.logger.LogDebug("Connection List Packet Received");

            var allConnections = server.AllConnections();
            var header         = UTF8Encoding.UTF8.GetBytes("=+ Connection List #" + allConnections.Count + System.Environment.NewLine);

            client.Send(header, 0, header.Length);
            foreach (var connection in allConnections)
            {
                var data = UTF8Encoding.UTF8.GetBytes(FormatConnectionRow(connection) + System.Environment.NewLine);
                client.Send(data, 0, data.Length);
            }

            var footer = UTF8Encoding.UTF8.GetBytes("=- Connection List" + System.Environment.NewLine);

            client.Send(footer, 0, footer.Length);
            return(Task.CompletedTask);
        }
Exemple #13
0
        internal void RequestAddPartyMemberTarget()
        {
            INetworkClient network = Service.Get <INetworkClient>();
            WorldModel     world   = Service.Get <WorldModel>();

            if (!InParty)
            {
                m_LeaderSerial = WorldModel.PlayerSerial;
                network.Send(new PartyRequestAddTargetPacket());
            }
            else if (InParty && PlayerIsLeader)
            {
                network.Send(new PartyRequestAddTargetPacket());
            }
            else if (InParty && !PlayerIsLeader)
            {
                world.Interaction.ChatMessage("You may only add members to the party if you are the leader.", 3, 10, false);
            }
        }
Exemple #14
0
        /// <summary>
        /// 网络集成测试
        /// </summary>
        public void NetworkIntergrateTest <T, V>(string connectStr)
            where T : INetworkServer, new()
            where V : INetworkClient, new()
        {
            //开启服务器
            INetworkServer server = NetworkFactory.CreateNetworkServer <T>();

            server.StartListen(connectStr);

            //测试用客户端进行连接
            INetworkClient client = null;

            ThreadPool.QueueUserWorkItem((o) => {
                Thread.Sleep(50); //假设50毫秒服务器可以开起来
                client = NetworkFactory.CreateNetworkClient <V>();
                client.Connect(connectStr);
            });

            //服务器获得新的session
            INetworkClientSession session = BlockWaitNewClient(server);

            Assert.IsNotNull(session);
            Assert.IsNotNull(client);
            Assert.IsTrue(client.Connected);

            //测试客户端往服务器发消息
            var testMsg = new GameMessage()
            {
                stateCode = 9999
            };

            client.Send(testMsg);
            var msg = BlockRead(session);

            Assert.AreEqual(msg.stateCode, 9999);

            //测试服务器往客户端发消息
            session.Send(new SyncMessage()
            {
                stateCode = 9993, timeleft = 3333
            });
            msg = BlockRead(client);
            Assert.IsTrue(msg is SyncMessage);
            Assert.AreEqual(msg.stateCode, 9993);
            Assert.AreEqual((msg as SyncMessage).timeleft, 3333);

            //关闭连接
            client.Close();
            Assert.IsFalse(client.Connected);
            session.Close();
            Assert.IsFalse(session.Connected);

            //关闭服务器
            server.Shutdown();
        }
        public override void ActivateByHREF(string href)
        {
            int contextMenuItemSelected;

            if (int.TryParse(href, out contextMenuItemSelected))
            {
                INetworkClient network = ServiceRegistry.GetService <INetworkClient>();
                network.Send(new ContextMenuResponsePacket(m_Data.Serial, (short)contextMenuItemSelected));
                this.Dispose();
            }
        }
Exemple #16
0
        public void LeaveParty()
        {
            INetworkClient network = Service.Get <INetworkClient>();

            network.Send(new PartyLeavePacket());
            m_PartyMembers.Clear();
            m_LeaderSerial = Serial.Null;
            UserInterfaceService ui = Service.Get <UserInterfaceService>();

            ui.RemoveControl <PartyHealthTrackerGump>();
        }
Exemple #17
0
 private void OnHello(INetworkClient client)
 {
     lock (mutex)
     {
         foreach (var msg in messages)
         {
             var data = UTF8Encoding.UTF8.GetBytes(msg);
             client.Send(data, 0, data.Length);
         }
     }
 }
Exemple #18
0
        //public void SendMsg_RequestVideoList()
        //{
        //    string sendData = TransferProtocol.Msg_RequestVideoList_CS("1");
        //    Send(sendData);
        //}
        //public void SendMsg_RequestUploadVideo(string msgData)
        //{
        //    string sendData = TransferProtocol.Msg_RequestUploadVideo_CS(msgData);
        //    Send(sendData);
        //}
        public void Send(string sendText)
        {
            if (sendText.Length <= 0)
            {
                Program.AddLog("Please type in something to send.");
            }
            byte[] bytes  = BytesFromString(sendText);
            Packet packet = new Packet(bytes, 0, bytes.Count(), false);

            m_client.Send(packet);
        }
        public void Send_Cmd(int sendcmd)
        {
            string test = " ";

            byte[] bytes = BytesFromString(test);
            //qt.Enqueue(sendcmd);
            bytes.SetValue((byte)sendcmd, 0);
            Packet packet = new Packet(bytes, 0, bytes.Count(), false);

            m_client.Send(packet);
        }
Exemple #20
0
 public void SetTargeting(TargetType targeting, int cursorID)
 {
     if (m_Targeting != targeting || cursorID != m_TargetID)
     {
         if (targeting == TargetType.Nothing)
         {
             m_Network.Send(new TargetCancelPacket());
         }
         else
         {
             // if we start targeting, we cancel movement.
             m_World.Input.ContinuousMouseMovementCheck = false;
         }
         m_Targeting = targeting;
         m_TargetID  = cursorID;
     }
 }
Exemple #21
0
        public void Send_Cmd(int sendcmd)
        {
            string test = " ";

            byte[] bytes = BytesFromString(test);
            if (m_client.IsConnectionAlive)
            {
                bytes.SetValue((byte)sendcmd, 0);
                Packet packet = new Packet(bytes, 0, bytes.Count(), false);
                m_client.Send(packet);
            }
        }
Exemple #22
0
        public void RemoveMember(Serial serial)
        {
            INetworkClient network = Service.Get <INetworkClient>();

            network.Send(new PartyRemoveMemberPacket(serial));
            int index = m_PartyMembers.FindIndex(p => p.Serial == serial);

            if (index != -1)
            {
                m_PartyMembers.RemoveAt(index);
            }
        }
Exemple #23
0
 internal void UpdateClient(INetworkClient client)
 {
     if (UnityEngine.Time.time - _lastPingTime >= PingInterval)
     {
         var pingMessage = new NetworkPingMessage
         {
             clientTime = LocalTime()
         };
         client.Send(pingMessage, Channel.Unreliable);
         _lastPingTime = UnityEngine.Time.time;
     }
 }
Exemple #24
0
        public void SendSpeech(string text, ChatMode mode) // used by chatwindow.
        {
            MessageTypes speechType = MessageTypes.Normal;
            int          hue        = 0;

            switch (mode)
            {
            case ChatMode.Default:
                speechType = MessageTypes.Normal;
                hue        = Settings.UserInterface.SpeechColor;
                break;

            case ChatMode.Whisper:
                speechType = MessageTypes.Whisper;
                hue        = Settings.UserInterface.SpeechColor;
                break;

            case ChatMode.Emote:
                speechType = MessageTypes.Emote;
                hue        = Settings.UserInterface.EmoteColor;
                break;

            case ChatMode.Party:
                // not yet implemented
                speechType = MessageTypes.Normal;
                hue        = Settings.UserInterface.SpeechColor;
                break;

            case ChatMode.Guild:
                speechType = MessageTypes.Guild;
                hue        = Settings.UserInterface.GuildMsgColor;
                break;

            case ChatMode.Alliance:
                speechType = MessageTypes.Alliance;
                hue        = Settings.UserInterface.AllianceMsgColor;
                break;
            }
            m_Network.Send(new AsciiSpeechPacket(speechType, 0, hue + 2, "ENU", text));
        }
Exemple #25
0
 public void SetTargeting(TargetType targeting, int cursorID, byte cursorType)
 {
     if (_targeting != targeting || cursorID != _targetCursorID || cursorType != _targetCursorType)
     {
         if (targeting == TargetType.Nothing)
         {
             _network.Send(new TargetCancelPacket(_targetCursorID, _targetCursorType));
         }
         // if we start targeting, we cancel movement.
         else
         {
             _world.Input.ContinuousMouseMovementCheck = false;
         }
         _targeting        = targeting;
         _targetCursorID   = cursorID;
         _targetCursorType = cursorType;
     }
 }
Exemple #26
0
        public override void OnKeyboardReturn(int textID, string text)
        {
            // local variables
            ChatMode     sentMode   = Mode;
            MessageTypes speechType = MessageTypes.Normal;
            int          hue        = 0;

            // save this message and reset chat for next entry
            m_TextEntry.Text = string.Empty;
            m_MessageHistory.Add(new Tuple <ChatMode, string>(Mode, text));
            m_MessageHistoryIndex = m_MessageHistory.Count;
            Mode = ChatMode.Default;
            // send the message and display it locally.
            switch (sentMode)
            {
            case ChatMode.Default:
                speechType = MessageTypes.Normal;
                hue        = Settings.UserInterface.SpeechColor;
                break;

            case ChatMode.Whisper:
                speechType = MessageTypes.Whisper;
                hue        = Settings.UserInterface.SpeechColor;
                break;

            case ChatMode.Emote:
                speechType = MessageTypes.Emote;
                hue        = Settings.UserInterface.EmoteColor;
                break;

            case ChatMode.Party:
                PlayerState.Partying.DoPartyCommand(text);
                return;

            case ChatMode.PartyPrivate:
                PlayerState.Partying.SendPartyPrivateMessage(m_PrivateMessageSerial, text);
                return;

            case ChatMode.Guild:
                speechType = MessageTypes.Guild;
                hue        = Settings.UserInterface.GuildMsgColor;
                break;

            case ChatMode.Alliance:
                speechType = MessageTypes.Alliance;
                hue        = Settings.UserInterface.AllianceMsgColor;
                break;
            }
            INetworkClient network = Service.Get <INetworkClient>();

            network.Send(new AsciiSpeechPacket(speechType, 0, hue + 2, "ENU", text));
        }
Exemple #27
0
        public void AddMember(Serial serial)
        {
            int index = m_PartyMembers.FindIndex(p => p.Serial == serial);

            if (index != -1)
            {
                m_PartyMembers.RemoveAt(index);
            }
            m_PartyMembers.Add(new PartyMember(serial));
            INetworkClient network = Service.Get <INetworkClient>();

            network.Send(new MobileQueryPacket(MobileQueryPacket.StatusType.BasicStatus, serial));
        }
Exemple #28
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            string sendText = tbSend.Text.Trim();

            if (sendText.Length <= 0)
            {
                MessageBox.Show("Please type in something to send.");
            }
            byte[] bytes  = BytesFromString(sendText);
            Packet packet = new Packet(bytes, 0, bytes.Count(), false);

            m_client.Send(packet);
        }
    public void Send(string msg)
    {
        if (msg == null)
        {
            throw new ArgumentNullException("msg");
        }
        if (Connected == false)
        {
            throw new InvalidOperationException("Not connected");
        }
        var buffer = Encoding.ASCII.GetBytes(msg + "\n");

        _networkClient.Send(buffer, 0, buffer.Length);
    }
Exemple #30
0
        public static void Toggle(Serial serial)
        {
            UserInterfaceService ui = Service.Get <UserInterfaceService>();

            if (ui.GetControl <StatusGump>() == null)
            {
                INetworkClient client = Service.Get <INetworkClient>();
                client.Send(new MobileQueryPacket(MobileQueryPacket.StatusType.BasicStatus, serial));
                ui.AddControl(new StatusGump(), 200, 400);
            }
            else
            {
                ui.RemoveControl <StatusGump>();
            }
        }
 /// <summary>
 /// Receive callback
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="receivedPacket">received packet</param>
 public void OnReceived(INetworkClient client, Packet receivedPacket)
 {
     ParallelPacket receivedParallelPacket = new ParallelPacket(receivedPacket);
     switch (receivedParallelPacket.PacketType)
     {
         case ParallelPacketType.DATA:
             if (ReceiveType == ReceiveType.BURST)
             {
                 OnParallelClientReceived(this, receivedParallelPacket);
             }
             else if (m_receiveType == ReceiveType.SEQUENTIAL)
             {
                 lock (m_receiveLock)
                 {
                     m_receivedQueue.Enqueue(receivedParallelPacket);
                     while (!m_receivedQueue.IsEmpty() && m_curReceivedPacketId + 1 == m_receivedQueue.Peek().PacketID)
                     {
                         ParallelPacket curPacket = m_receivedQueue.Dequeue();
                         m_curReceivedPacketId = curPacket.PacketID;
                         if (m_curReceivedPacketId == long.MaxValue)
                         {
                             m_curReceivedPacketId = -1;
                         }
                         OnParallelClientReceived(this, curPacket);
                     }
                 }
             }
             break;
         case ParallelPacketType.IDENTITY_REQUEST:
             PacketSerializer<IdentityResponse> serializer = new PacketSerializer<IdentityResponse>(new IdentityResponse(Guid,MaxSocketCount));
             ParallelPacket sendPacket=new ParallelPacket(-1,ParallelPacketType.IDENTITY_RESPONSE,serializer.PacketRaw);
             client.Send(sendPacket.PacketRaw);
             break;
         case ParallelPacketType.READY:
             lock (m_sendLock)
             {
                 m_pendingClientSet.Add(client);
                 if (m_pendingClientSet.Count > 0 && (m_errorPacketSet.Count > 0 || m_packetQueue.Count > 0))
                     m_sendReadyEvent.SetEvent();
             }
             break;
     }
 }
        /// <summary>
        /// Receive callback
        /// </summary>
        /// <param name="client">client</param>
        /// <param name="receivedPacket">received packet</param>
        public void OnReceived(INetworkClient client, Packet receivedPacket)
        {
            ParallelPacket receivedParallelPacket = new ParallelPacket(receivedPacket);
            switch (receivedParallelPacket.GetPacketType())
            {
                case ParallelPacketType.DATA:
                    if (m_receiveType == ReceiveType.BURST)
                    {
                        if (CallBackObj != null)
                        {
//                             Task t = new Task(delegate()
//                             {
//                                 CallBackObj.OnReceived(this, receivedParallelPacket);
//                             });
//                             t.Start();
                            CallBackObj.OnReceived(this, receivedParallelPacket);
                        }
                    }
                    else if (m_receiveType == ReceiveType.SEQUENTIAL)
                    {
                        lock (m_receiveLock)
                        {
                            m_receivedQueue.Enqueue(receivedParallelPacket);
                            while (m_curReceivedPacketId == -1 || (!m_receivedQueue.IsEmpty() && m_curReceivedPacketId + 1 == m_receivedQueue.Peek().GetPacketID()))
                            {
                                ParallelPacket curPacket = m_receivedQueue.Dequeue();
                                m_curReceivedPacketId = curPacket.GetPacketID();
                                if (CallBackObj != null)
                                {
//                                     Task t = new Task(delegate()
//                                     {
//                                         CallBackObj.OnReceived(this, curPacket);
//                                     });
//                                     t.Start();
                                    m_callBackObj.OnReceived(this, curPacket);
                                }
                            }
                        }
                    }
                    break;
                case ParallelPacketType.IDENTITY_REQUEST:
                    PacketSerializer<IdentityResponse> serializer = new PacketSerializer<IdentityResponse>(new IdentityResponse(Guid));
                    ParallelPacket sendPacket=new ParallelPacket(getCurPacketSequence(),ParallelPacketType.IDENTITY_RESPONSE,serializer.GetPacketRaw());
                    client.Send(sendPacket.GetPacketRaw());
                    break;
                case ParallelPacketType.READY:
                    lock (m_sendLock)
                    {
                        m_pendingClientSet.Add(client);
                        if (m_pendingClientSet.Count > 0 && (m_errorPacketSet.Count > 0 || m_packetQueue.Count > 0))
                            m_sendReadyEvent.SetEvent();
                    }
                    break;
            }
        }