Browse Source

聊天服务器增加指定Nickname单独发送消息的接口.

gwang 3 years ago
parent
commit
25fef4e726
3 changed files with 82 additions and 14 deletions
  1. 5 2
      CSserver/PBReferens/pb/chat.proto
  2. 71 10
      CSserver/PBReferens/pbcs/Chat.cs
  3. 6 2
      CSserver/csserver/Program.cs

+ 5 - 2
CSserver/PBReferens/pb/chat.proto

@@ -11,6 +11,9 @@ enum ChatChannel {
 	World = 1;
 	// 公会频道
 	Guild =2;
+	// 密语(单独发送给某人)
+	Single =3;
+
 }
 
 // 聊天, 登录
@@ -24,10 +27,9 @@ message CS_ChatLogin
 // 聊天, 发送消息
 message CS_ChatSendMsg
 {
-  
 	ChatChannel ToChannel = 1;
 	string  Msg = 2;
-
+	string ToNickName=3;
 }
 
 // 聊天, 初始化返回值
@@ -55,4 +57,5 @@ message SC_ChatNewMsg
 	ChatChannel FromChannel = 1;
 	string Msg = 2; 
 	string SenderName = 3;
+	string SenderUid = 4;
 }

+ 71 - 10
CSserver/PBReferens/pbcs/Chat.cs

@@ -23,22 +23,23 @@ namespace Chat {
       byte[] descriptorData = global::System.Convert.FromBase64String(
           string.Concat(
             "Cg1wYi9jaGF0LnByb3RvEgRDaGF0IjkKDENTX0NoYXRMb2dpbhIOCgZab25l",
-            "aWQYASABKAUSCwoDVWlkGAIgASgJEgwKBE5hbWUYAyABKAkiQwoOQ1NfQ2hh",
+            "aWQYASABKAUSCwoDVWlkGAIgASgJEgwKBE5hbWUYAyABKAkiVwoOQ1NfQ2hh",
             "dFNlbmRNc2cSJAoJVG9DaGFubmVsGAEgASgOMhEuQ2hhdC5DaGF0Q2hhbm5l",
-            "bBILCgNNc2cYAiABKAkiggEKDFNDX0NoYXRMb2dpbhIqCgRjb2RlGAEgASgO",
-            "MhwuQ2hhdC5TQ19DaGF0TG9naW4uRXJyb3JDb2RlIkYKCUVycm9yQ29kZRIG",
-            "CgJPSxAAEhAKDEFjY0lESW52YWxpZBABEg8KC0xvZ2luUmVwZWF0EAISDgoK",
-            "SW5uZXJFcnJvchADIlgKDVNDX0NoYXROZXdNc2cSJgoLRnJvbUNoYW5uZWwY",
-            "ASABKA4yES5DaGF0LkNoYXRDaGFubmVsEgsKA01zZxgCIAEoCRISCgpTZW5k",
-            "ZXJOYW1lGAMgASgJKi8KC0NoYXRDaGFubmVsEgoKBlN5c3RlbRAAEgkKBVdv",
-            "cmxkEAESCQoFR3VpbGQQAmIGcHJvdG8z"));
+            "bBILCgNNc2cYAiABKAkSEgoKVG9OaWNrTmFtZRgDIAEoCSKCAQoMU0NfQ2hh",
+            "dExvZ2luEioKBGNvZGUYASABKA4yHC5DaGF0LlNDX0NoYXRMb2dpbi5FcnJv",
+            "ckNvZGUiRgoJRXJyb3JDb2RlEgYKAk9LEAASEAoMQWNjSURJbnZhbGlkEAES",
+            "DwoLTG9naW5SZXBlYXQQAhIOCgpJbm5lckVycm9yEAMiawoNU0NfQ2hhdE5l",
+            "d01zZxImCgtGcm9tQ2hhbm5lbBgBIAEoDjIRLkNoYXQuQ2hhdENoYW5uZWwS",
+            "CwoDTXNnGAIgASgJEhIKClNlbmRlck5hbWUYAyABKAkSEQoJU2VuZGVyVWlk",
+            "GAQgASgJKjsKC0NoYXRDaGFubmVsEgoKBlN5c3RlbRAAEgkKBVdvcmxkEAES",
+            "CQoFR3VpbGQQAhIKCgZTaW5nbGUQA2IGcHJvdG8z"));
       descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
           new pbr::FileDescriptor[] { },
           new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Chat.ChatChannel), }, new pbr::GeneratedClrTypeInfo[] {
             new pbr::GeneratedClrTypeInfo(typeof(global::Chat.CS_ChatLogin), global::Chat.CS_ChatLogin.Parser, new[]{ "Zoneid", "Uid", "Name" }, null, null, null),
-            new pbr::GeneratedClrTypeInfo(typeof(global::Chat.CS_ChatSendMsg), global::Chat.CS_ChatSendMsg.Parser, new[]{ "ToChannel", "Msg" }, null, null, null),
+            new pbr::GeneratedClrTypeInfo(typeof(global::Chat.CS_ChatSendMsg), global::Chat.CS_ChatSendMsg.Parser, new[]{ "ToChannel", "Msg", "ToNickName" }, null, null, null),
             new pbr::GeneratedClrTypeInfo(typeof(global::Chat.SC_ChatLogin), global::Chat.SC_ChatLogin.Parser, new[]{ "Code" }, null, new[]{ typeof(global::Chat.SC_ChatLogin.Types.ErrorCode) }, null),
-            new pbr::GeneratedClrTypeInfo(typeof(global::Chat.SC_ChatNewMsg), global::Chat.SC_ChatNewMsg.Parser, new[]{ "FromChannel", "Msg", "SenderName" }, null, null, null)
+            new pbr::GeneratedClrTypeInfo(typeof(global::Chat.SC_ChatNewMsg), global::Chat.SC_ChatNewMsg.Parser, new[]{ "FromChannel", "Msg", "SenderName", "SenderUid" }, null, null, null)
           }));
     }
     #endregion
@@ -61,6 +62,10 @@ namespace Chat {
     /// 公会频道
     /// </summary>
     [pbr::OriginalName("Guild")] Guild = 2,
+    /// <summary>
+    /// 密语(单独发送给某人)
+    /// </summary>
+    [pbr::OriginalName("Single")] Single = 3,
   }
 
   #endregion
@@ -271,6 +276,7 @@ namespace Chat {
     public CS_ChatSendMsg(CS_ChatSendMsg other) : this() {
       toChannel_ = other.toChannel_;
       msg_ = other.msg_;
+      toNickName_ = other.toNickName_;
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -300,6 +306,17 @@ namespace Chat {
       }
     }
 
+    /// <summary>Field number for the "ToNickName" field.</summary>
+    public const int ToNickNameFieldNumber = 3;
+    private string toNickName_ = "";
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public string ToNickName {
+      get { return toNickName_; }
+      set {
+        toNickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+      }
+    }
+
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public override bool Equals(object other) {
       return Equals(other as CS_ChatSendMsg);
@@ -315,6 +332,7 @@ namespace Chat {
       }
       if (ToChannel != other.ToChannel) return false;
       if (Msg != other.Msg) return false;
+      if (ToNickName != other.ToNickName) return false;
       return true;
     }
 
@@ -323,6 +341,7 @@ namespace Chat {
       int hash = 1;
       if (ToChannel != 0) hash ^= ToChannel.GetHashCode();
       if (Msg.Length != 0) hash ^= Msg.GetHashCode();
+      if (ToNickName.Length != 0) hash ^= ToNickName.GetHashCode();
       return hash;
     }
 
@@ -341,6 +360,10 @@ namespace Chat {
         output.WriteRawTag(18);
         output.WriteString(Msg);
       }
+      if (ToNickName.Length != 0) {
+        output.WriteRawTag(26);
+        output.WriteString(ToNickName);
+      }
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -352,6 +375,9 @@ namespace Chat {
       if (Msg.Length != 0) {
         size += 1 + pb::CodedOutputStream.ComputeStringSize(Msg);
       }
+      if (ToNickName.Length != 0) {
+        size += 1 + pb::CodedOutputStream.ComputeStringSize(ToNickName);
+      }
       return size;
     }
 
@@ -366,6 +392,9 @@ namespace Chat {
       if (other.Msg.Length != 0) {
         Msg = other.Msg;
       }
+      if (other.ToNickName.Length != 0) {
+        ToNickName = other.ToNickName;
+      }
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -384,6 +413,10 @@ namespace Chat {
             Msg = input.ReadString();
             break;
           }
+          case 26: {
+            ToNickName = input.ReadString();
+            break;
+          }
         }
       }
     }
@@ -572,6 +605,7 @@ namespace Chat {
       fromChannel_ = other.fromChannel_;
       msg_ = other.msg_;
       senderName_ = other.senderName_;
+      senderUid_ = other.senderUid_;
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -612,6 +646,17 @@ namespace Chat {
       }
     }
 
+    /// <summary>Field number for the "SenderUid" field.</summary>
+    public const int SenderUidFieldNumber = 4;
+    private string senderUid_ = "";
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public string SenderUid {
+      get { return senderUid_; }
+      set {
+        senderUid_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+      }
+    }
+
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public override bool Equals(object other) {
       return Equals(other as SC_ChatNewMsg);
@@ -628,6 +673,7 @@ namespace Chat {
       if (FromChannel != other.FromChannel) return false;
       if (Msg != other.Msg) return false;
       if (SenderName != other.SenderName) return false;
+      if (SenderUid != other.SenderUid) return false;
       return true;
     }
 
@@ -637,6 +683,7 @@ namespace Chat {
       if (FromChannel != 0) hash ^= FromChannel.GetHashCode();
       if (Msg.Length != 0) hash ^= Msg.GetHashCode();
       if (SenderName.Length != 0) hash ^= SenderName.GetHashCode();
+      if (SenderUid.Length != 0) hash ^= SenderUid.GetHashCode();
       return hash;
     }
 
@@ -659,6 +706,10 @@ namespace Chat {
         output.WriteRawTag(26);
         output.WriteString(SenderName);
       }
+      if (SenderUid.Length != 0) {
+        output.WriteRawTag(34);
+        output.WriteString(SenderUid);
+      }
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -673,6 +724,9 @@ namespace Chat {
       if (SenderName.Length != 0) {
         size += 1 + pb::CodedOutputStream.ComputeStringSize(SenderName);
       }
+      if (SenderUid.Length != 0) {
+        size += 1 + pb::CodedOutputStream.ComputeStringSize(SenderUid);
+      }
       return size;
     }
 
@@ -690,6 +744,9 @@ namespace Chat {
       if (other.SenderName.Length != 0) {
         SenderName = other.SenderName;
       }
+      if (other.SenderUid.Length != 0) {
+        SenderUid = other.SenderUid;
+      }
     }
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -712,6 +769,10 @@ namespace Chat {
             SenderName = input.ReadString();
             break;
           }
+          case 34: {
+            SenderUid = input.ReadString();
+            break;
+          }
         }
       }
     }

+ 6 - 2
CSserver/csserver/Program.cs

@@ -72,10 +72,10 @@ namespace ChatServer
             if (Peers.TryGetValue(peerKey, out Peer p))
             {
                 var msg = CS_ChatSendMsg.Parser.ParseFrom(data._data);
-                if (null != msg)
+                if (null != msg &&  msg.Msg.Trim().Length>0)
                 {
                     var rdb = Redis.Ins.GetDatabase(0);
-                    var sd = new SC_ChatNewMsg() { FromChannel = msg.ToChannel, SenderName = p.Name, Msg = msg.Msg };
+                    var sd = new SC_ChatNewMsg() { FromChannel = msg.ToChannel, SenderName = p.Name, Msg = msg.Msg, SenderUid = p.UID };
                     switch (msg.ToChannel)
                     {
                         case ChatChannel.System:    // 这个一般是客户端生成的, 除非是GM号,一般人发送这种消息拒绝转发.
@@ -117,6 +117,10 @@ namespace ChatServer
                             }
 
                             break;
+
+                        case ChatChannel.Single:
+                            Peers.Values.Where(peer =>peer.Name == msg.ToNickName).ToList().ForEach(_p => _p.SendEvent(eProtocalCommand.ScChatNewMsg, sd));
+                            break;
                         default:
                             Console.WriteLine("chat:未知的发送目标");
                             break;