private void Manager_MessageArrivedEvent(object sender, MessageDictionary e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                if (messageListSP.Children.Count >= maxMesListLen)
                {
                    messageListSP.Children.RemoveAt(0);
                }
                if ((CommandType)Enum.Parse(typeof(CommandType), e[MesKeyStr.CommandType]) == CommandType.GroupMessage)
                {
                    e.Add(MesKeyStr.Remark, "群聊消息");
                }
                else
                {
                    e.Add(MesKeyStr.Remark, "私聊消息,目标:" + e[MesKeyStr.UserID]);
                }

                DisplayMethod displayMethod = DisplayMethod.OnlyRemark;
                if (displayStyle)
                {
                    displayMethod = DisplayMethod.Both;
                }
                MessageUC messageUC = new MessageUC(e, displayMethod);
                messageListSP.Children.Add(messageUC);
                messageListSV.ScrollToEnd();
            });
        }
Exemple #2
0
        public bool SendServerClosingMessage(Socket socket)
        {
            MessageDictionary messageD = new MessageDictionary();

            messageD.Add(MesKeyStr.CommandType, CommandType.ServerDisconnect.ToString());
            return(Send(socket, messageD.ToString()));
        }
Exemple #3
0
 public bool SendSignUpResult(Socket socket, string userID)
 {
     try
     {
         MessageDictionary messageD = new MessageDictionary();
         messageD.Add(MesKeyStr.CommandType, CommandType.SignUpResult.ToString());
         messageD.Add(MesKeyStr.SignUpResult, userID);
         Send(socket, messageD.ToString());
         return(true);
     }
     catch (Exception e)
     {
         ShowMessage("发送" + userID + "的注册结果失败:" + e.Message + "\n" + e.StackTrace + "\n");
         return(false);
     }
 }
Exemple #4
0
 public bool SendLoginResult(UserSocket userSocket, bool result)
 {
     try
     {
         MessageDictionary messageD = new MessageDictionary();
         messageD.Add(MesKeyStr.CommandType, CommandType.LoginResult.ToString());
         messageD.Add(MesKeyStr.LoginResult, result.ToString());
         messageD.Add(MesKeyStr.UserID, userSocket.UserID);
         messageD.Add(MesKeyStr.NickName, userSocket.NickName);
         Send(userSocket.Socket, messageD.ToString());
         return(true);
     }
     catch (Exception e)
     {
         ShowMessage("发送登录结果失败" + e.Message + "\n" + e.StackTrace + "\n");
         return(false);
     }
 }
Exemple #5
0
 private void Connector_PrivateMessageEvent(object sender, MessageDictionary e)
 {
     for (int i = 0; i < LoginedUserList.Count; i++)
     {
         if (LoginedUserList[i].UserID.Equals(e[MesKeyStr.TargetUserID]))
         {
             UserSocket user = GetUserSocket(e[MesKeyStr.UserID]);
             string     ip   = ((IPEndPoint)user.Socket.RemoteEndPoint).Address.ToString();
             e.Add(MesKeyStr.NickName, user.NickName);
             e.Add(MesKeyStr.IP, ip);
             e.Add(MesKeyStr.DateTime, DateTime.Now.ToString());
             MessageArrivedEvent?.Invoke(this, e);
             e.Add(MesKeyStr.Sender, Sender.self.ToString());
             connector.SendMessage(user.Socket, e);
             e[MesKeyStr.Sender] = Sender.others.ToString();
             connector.SendMessage(LoginedUserList[i].Socket, e);
         }
     }
 }
Exemple #6
0
        private void Connector_GroupMessageEvent(object sender, MessageDictionary e)
        {
            UserSocket user = GetUserSocket(e[MesKeyStr.UserID]);
            string     ip   = ((IPEndPoint)user.Socket.RemoteEndPoint).Address.ToString();

            e.Add(MesKeyStr.NickName, user.NickName);
            e.Add(MesKeyStr.IP, ip);
            e.Add(MesKeyStr.DateTime, DateTime.Now.ToString());
            MessageArrivedEvent?.Invoke(this, e);
            e.Add(MesKeyStr.Sender, Sender.others.ToString());
            foreach (UserSocket u in LoginedUserList)
            {
                if (u.UserID.Equals(e[MesKeyStr.UserID]))
                {
                    continue;
                }
                connector.SendMessage(u.Socket, e);
            }
            e[MesKeyStr.Sender] = Sender.self.ToString();
            connector.SendMessage(user.Socket, e);
        }
        /// <summary>
        /// Copies some extra parameters into a message.
        /// </summary>
        /// <param name="messageDictionary">The message to copy the extra data into.</param>
        /// <param name="extraParameters">The extra data to copy into the message.  May be null to do nothing.</param>
        internal static void AddExtraParameters(this MessageDictionary messageDictionary, IDictionary <string, string> extraParameters)
        {
            Contract.Requires <ArgumentNullException>(messageDictionary != null);

            if (extraParameters != null)
            {
                foreach (var pair in extraParameters)
                {
                    messageDictionary.Add(pair);
                }
            }
        }
        /// <summary>
        /// Copies some extra parameters into a message.
        /// </summary>
        /// <param name="message">The message to copy the extra data into.</param>
        /// <param name="extraParameters">The extra data to copy into the message.  May be null to do nothing.</param>
        internal static void AddExtraParameters(this IMessage message, IDictionary <string, string> extraParameters)
        {
            ErrorUtilities.VerifyArgumentNotNull(message, "message");

            if (extraParameters != null)
            {
                MessageDictionary messageDictionary = new MessageDictionary(message);
                foreach (var pair in extraParameters)
                {
                    messageDictionary.Add(pair);
                }
            }
        }
Exemple #9
0
        public bool SendUserChange(UserSocket oldUserSocket, User newUser, CommandType commandType)
        {
            if (commandType != CommandType.UserJoin && commandType != CommandType.UserQuit)
            {
                ShowMessage("发送用户变化错误,非法的命令类型");
                return(false);
            }

            MessageDictionary messageD = new MessageDictionary();

            messageD.Add(MesKeyStr.CommandType, commandType.ToString());
            messageD.Add(MesKeyStr.UserID, newUser.UserID);
            messageD.Add(MesKeyStr.NickName, newUser.NickName);
            try
            {
                Send(oldUserSocket.Socket, messageD.ToString());
                return(true);
            }
            catch (Exception e)
            {
                ShowMessage("发送用户变化错误" + e.Message + "\n" + e.StackTrace + "\n");
                return(false);
            }
        }
Exemple #10
0
        private static MessageDictionary MessageCallback()
        {
            var result      = new MessageDictionary();
            var messageData = ServiceLocator.Resolve <IErrorMessageManagement>().ListAll().Data;

            foreach (var message in messageData)
            {
                if (!result.ContainsKey(message.BranchID))
                {
                    result.Add(message.BranchID, new List <Message>());
                }

                result[message.BranchID].Add(new Message(message.MessageID, message.VNMessage, message.ENMessage));
            }

            return(result);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="compress">Compress the messages or not</param>
 public ClientMessageFactory(bool compress) : base(compress)
 {
     MessageDictionary.Add((uint)ClientMessageType.HANDSHAKE, new HandshakeCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.CHAT, new ChatCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.PLAYER_STATUS, new PlayerStatusCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.PLAYER_COLOR, new PlayerColorCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.SCENARIO, new ScenarioCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.KERBAL, new KerbalCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.SETTINGS, new SettingsCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.VESSEL, new VesselCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.CRAFT_LIBRARY, new CraftLibraryCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.FLAG, new FlagCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.SYNC_TIME, new SyncTimeCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.MOTD, new MotdCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.WARP, new WarpCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.LOCK, new LockCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.MOD, new ModCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.ADMIN, new AdminCliMsg());
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="compress">Compress the messages or not</param>
 public ClientMessageFactory(bool compress) : base(compress)
 {
     MessageDictionary.Add((uint)ClientMessageType.Handshake, new HandshakeCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Chat, new ChatCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.PlayerStatus, new PlayerStatusCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.PlayerColor, new PlayerColorCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Scenario, new ScenarioCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Kerbal, new KerbalCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Settings, new SettingsCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Vessel, new VesselCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.CraftLibrary, new CraftLibraryCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Flag, new FlagCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.SyncTime, new SyncTimeCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Motd, new MotdCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Warp, new WarpCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Lock, new LockCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Mod, new ModCliMsg());
     MessageDictionary.Add((uint)ClientMessageType.Admin, new AdminCliMsg());
 }
Exemple #13
0
 public ClientMessageFactory()
 {
     MessageDictionary.Add((uint)ClientMessageType.Handshake, typeof(HandshakeCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Chat, typeof(ChatCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.PlayerStatus, typeof(PlayerStatusCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.PlayerColor, typeof(PlayerColorCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Scenario, typeof(ScenarioCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Kerbal, typeof(KerbalCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Settings, typeof(SettingsCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Vessel, typeof(VesselCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.CraftLibrary, typeof(CraftLibraryCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Flag, typeof(FlagCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Motd, typeof(MotdCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Warp, typeof(WarpCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Lock, typeof(LockCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Mod, typeof(ModCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Admin, typeof(AdminCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Groups, typeof(GroupCliMsg));
     MessageDictionary.Add((uint)ClientMessageType.Facility, typeof(FacilityCliMsg));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="compress">Compress the messages or not</param>
 public ServerMessageFactory(bool compress) : base(compress)
 {
     MessageDictionary.Add((uint)ServerMessageType.Handshake, new HandshakeSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Settings, new SetingsSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Chat, new ChatSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PlayerStatus, new PlayerStatusSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PlayerColor, new PlayerColorSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PlayerConnection, new PlayerConnectionSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Scenario, new ScenarioSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Kerbal, new KerbalSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Vessel, new VesselSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.CraftLibrary, new CraftLibrarySrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Flag, new FlagSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.SyncTime, new SyncTimeSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Motd, new MotdSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Warp, new WarpSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Admin, new AdminSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Lock, new LockSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.Mod, new ModSrvMsg());
 }
Exemple #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="compress">Compress the messages or not</param>
 public ServerMessageFactory(bool compress) : base(compress)
 {
     MessageDictionary.Add((uint)ServerMessageType.HANDSHAKE, new HandshakeSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.SETTINGS, new SetingsSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.CHAT, new ChatSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PLAYER_STATUS, new PlayerStatusSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PLAYER_COLOR, new PlayerColorSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.PLAYER_CONNECTION, new PlayerConnectionSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.SCENARIO, new ScenarioSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.KERBAL, new KerbalSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.VESSEL, new VesselSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.CRAFT_LIBRARY, new CraftLibrarySrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.FLAG, new FlagSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.SYNC_TIME, new SyncTimeSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.MOTD, new MotdSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.WARP, new WarpSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.ADMIN, new AdminSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.LOCK, new LockSrvMsg());
     MessageDictionary.Add((uint)ServerMessageType.MOD, new ModSrvMsg());
 }
Exemple #16
0
 public ServerMessageFactory()
 {
     MessageDictionary.Add((uint)ServerMessageType.Handshake, typeof(HandshakeSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Settings, typeof(SetingsSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Chat, typeof(ChatSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.PlayerStatus, typeof(PlayerStatusSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.PlayerColor, typeof(PlayerColorSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.PlayerConnection, typeof(PlayerConnectionSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Scenario, typeof(ScenarioSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Kerbal, typeof(KerbalSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Vessel, typeof(VesselSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.CraftLibrary, typeof(CraftLibrarySrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Flag, typeof(FlagSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Motd, typeof(MotdSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Warp, typeof(WarpSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Admin, typeof(AdminSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Lock, typeof(LockSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Mod, typeof(ModSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Groups, typeof(GroupSrvMsg));
     MessageDictionary.Add((uint)ServerMessageType.Facility, typeof(FacilitySrvMsg));
 }
Exemple #17
0
 /// <inheritdoc />
 public MasterServerMessageFactory()
 {
     MessageDictionary.Add((uint)MasterServerMessageType.Main, typeof(MainMstSrvMsg));
 }
Exemple #18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="compress">Compress the messages or not</param>
 public MasterServerMessageFactory(bool compress) : base(compress)
 {
     MessageDictionary.Add((uint)MasterServerMessageType.MAIN, new MainMstSrvMsg());
 }