Esempio n. 1
0
        public bool SendServerClosingMessage(Socket socket)
        {
            MessageDictionary messageD = new MessageDictionary();

            messageD.Add(MesKeyStr.CommandType, CommandType.ServerDisconnect.ToString());
            return(Send(socket, messageD.ToString()));
        }
Esempio n. 2
0
 public bool SendMessage(Socket socket, MessageDictionary chatMessage)
 {
     if (Send(socket, chatMessage.ToString()))
     {
         return(true);
     }
     else
     {
         ShowMessage("发送信息失败");
         return(false);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 5
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);
            }
        }