This commit is contained in:
sin365 2023-05-25 13:24:51 +08:00
parent 3be84a1318
commit fb264af37b
30 changed files with 1090 additions and 58 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,18 +1,41 @@
using ClientCore; using ClientCore;
ClientManager.Init("127.0.0.1", 23846); App.Init("127.0.0.1", 23846);
//注册
App.chat.OnChatMsg += OnChatMsg;
while (true) while (true)
{ {
string CommandStr = Console.ReadLine(); string CommandStr = Console.ReadLine();
string Command = ""; string Command = "";
Command = ((CommandStr.IndexOf(" ") <= 0) ? CommandStr : CommandStr.Substring(0, CommandStr.IndexOf(" "))); Command = ((CommandStr.IndexOf(" ") <= 0) ? CommandStr : CommandStr.Substring(0, CommandStr.IndexOf(" ")));
string[] CmdArr = CommandStr.Split(' ');
switch (Command) switch (Command)
{ {
case "login": case "login":
StaticComm.login.Login(); case "l":
if (CmdArr.Length < 2)
{
Console.WriteLine("缺省用户名");
return;
}
App.login.Login(CmdArr[1]);
break;
case "say":
if (CmdArr.Length < 2)
{
Console.WriteLine("缺省参数");
return;
}
App.chat.SendChatMsg(CmdArr[1]);
break; break;
default: default:
Console.WriteLine("未知命令" + CommandStr); Console.WriteLine("未知命令" + CommandStr);
break; break;
} }
} }
void OnChatMsg(string str1, string str2)
{
Console.WriteLine($"[Chat]{str1}:{str2}");
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ClientCore namespace ClientCore
{ {
public class StaticComm public class App
{ {
public static string TokenStr; public static string TokenStr;
public static long RID = -1; public static long RID = -1;
@ -14,5 +14,16 @@ namespace ClientCore
public static int Port; public static int Port;
public static NetworkHelper networkHelper; public static NetworkHelper networkHelper;
public static AppLogin login; public static AppLogin login;
public static AppChat chat;
public static void Init(string IP, int port)
{
networkHelper = new NetworkHelper();
login = new AppLogin();
chat = new AppChat();
networkHelper.Init(IP, port);
} }
}
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HaoYueNet.ClientNetwork.NetworkHelperCore;
namespace ClientCore.Event
{
public class DelegateClass
{
public delegate void dg_Str(string Msg);
public delegate void dg_Str_Str(string Str1, string Str2);
}
}

View File

@ -0,0 +1,27 @@
using AxibugProtobuf;
using System.Net.Sockets;
using static ClientCore.Event.DelegateClass;
using static HaoYueNet.ClientNetwork.NetworkHelperCore;
namespace ClientCore
{
public class AppChat
{
public event dg_Str_Str OnChatMsg;
public void SendChatMsg(string ChatMsg)
{
Protobuf_ChatMsg msg = new Protobuf_ChatMsg()
{
ChatMsg = ChatMsg,
};
App.networkHelper.SendToServer((int)CommandID.CmdChatmsg, NetBase.Serizlize(msg));
}
public void RecvChatMsg(byte[] reqData)
{
Protobuf_ChatMsg_RESP msg = NetBase.DeSerizlize<Protobuf_ChatMsg_RESP>(reqData);
OnChatMsg(msg.NickName, msg.ChatMsg);
}
}
}

View File

@ -4,14 +4,14 @@ namespace ClientCore
{ {
public class AppLogin public class AppLogin
{ {
public void Login() public void Login(string Account)
{ {
Protobuf_Login msg = new Protobuf_Login() Protobuf_Login msg = new Protobuf_Login()
{ {
LoginType = 0, LoginType = 0,
//TODO Account = Account,
}; };
StaticComm.networkHelper.SendToServer((int)CommandID.CmdLogin, NetBase.Serizlize(msg)); App.networkHelper.SendToServer((int)CommandID.CmdLogin, NetBase.Serizlize(msg));
} }
} }
} }

View File

@ -1,12 +0,0 @@
namespace ClientCore
{
public static class ClientManager
{
public static void Init(string IP,int port)
{
StaticComm.networkHelper = new NetworkHelper();
StaticComm.login = new AppLogin();
StaticComm.networkHelper.Init(IP, port);
}
}
}

View File

@ -59,6 +59,7 @@ namespace ClientCore
switch ((CommandID)CMDID) switch ((CommandID)CMDID)
{ {
case CommandID.CmdLogin: break; case CommandID.CmdLogin: break;
case CommandID.CmdChatmsg: App.chat.RecvChatMsg(data); break;
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -30,20 +30,25 @@ namespace AxibugProtobuf {
"b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY", "b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY",
"BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV", "BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV",
"Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh", "Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh",
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMq", "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"KwoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURfTE9HSU4Q0Q8q", "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq", "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB", "GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB",
"EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw", "VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy",
"ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD", "b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n",
"UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0", "aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi", "MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh",
"BnByb3RvMw==")); "dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv",
"Mw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null) new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg), global::AxibugProtobuf.Protobuf_ChatMsg.Parser, new[]{ "ChatMsg" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg_RESP), global::AxibugProtobuf.Protobuf_ChatMsg_RESP.Parser, new[]{ "NickName", "ChatMsg", "Date" }, null, null, null, null)
})); }));
} }
#endregion #endregion
@ -59,6 +64,10 @@ namespace AxibugProtobuf {
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP ///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001, [pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001,
/// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001,
} }
public enum ErrorCode { public enum ErrorCode {
@ -695,6 +704,440 @@ namespace AxibugProtobuf {
} }
/// <summary>
///聊天 上行
/// </summary>
public sealed partial class Protobuf_ChatMsg : pb::IMessage<Protobuf_ChatMsg>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_ChatMsg> _parser = new pb::MessageParser<Protobuf_ChatMsg>(() => new Protobuf_ChatMsg());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_ChatMsg> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufAuthReflection.Descriptor.MessageTypes[2]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg(Protobuf_ChatMsg other) : this() {
chatMsg_ = other.chatMsg_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg Clone() {
return new Protobuf_ChatMsg(this);
}
/// <summary>Field number for the "ChatMsg" field.</summary>
public const int ChatMsgFieldNumber = 1;
private string chatMsg_ = "";
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ChatMsg {
get { return chatMsg_; }
set {
chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_ChatMsg);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_ChatMsg other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (ChatMsg != other.ChatMsg) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (ChatMsg.Length != 0) hash ^= ChatMsg.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (ChatMsg.Length != 0) {
output.WriteRawTag(10);
output.WriteString(ChatMsg);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (ChatMsg.Length != 0) {
output.WriteRawTag(10);
output.WriteString(ChatMsg);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (ChatMsg.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_ChatMsg other) {
if (other == null) {
return;
}
if (other.ChatMsg.Length != 0) {
ChatMsg = other.ChatMsg;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
ChatMsg = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
ChatMsg = input.ReadString();
break;
}
}
}
}
#endif
}
/// <summary>
///聊天 下行
/// </summary>
public sealed partial class Protobuf_ChatMsg_RESP : pb::IMessage<Protobuf_ChatMsg_RESP>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_ChatMsg_RESP> _parser = new pb::MessageParser<Protobuf_ChatMsg_RESP>(() => new Protobuf_ChatMsg_RESP());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_ChatMsg_RESP> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufAuthReflection.Descriptor.MessageTypes[3]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP(Protobuf_ChatMsg_RESP other) : this() {
nickName_ = other.nickName_;
chatMsg_ = other.chatMsg_;
date_ = other.date_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP Clone() {
return new Protobuf_ChatMsg_RESP(this);
}
/// <summary>Field number for the "NickName" field.</summary>
public const int NickNameFieldNumber = 1;
private string nickName_ = "";
/// <summary>
///昵称
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string NickName {
get { return nickName_; }
set {
nickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "ChatMsg" field.</summary>
public const int ChatMsgFieldNumber = 2;
private string chatMsg_ = "";
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ChatMsg {
get { return chatMsg_; }
set {
chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "Date" field.</summary>
public const int DateFieldNumber = 3;
private long date_;
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long Date {
get { return date_; }
set {
date_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_ChatMsg_RESP);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_ChatMsg_RESP other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (NickName != other.NickName) return false;
if (ChatMsg != other.ChatMsg) return false;
if (Date != other.Date) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (NickName.Length != 0) hash ^= NickName.GetHashCode();
if (ChatMsg.Length != 0) hash ^= ChatMsg.GetHashCode();
if (Date != 0L) hash ^= Date.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (NickName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(NickName);
}
if (ChatMsg.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ChatMsg);
}
if (Date != 0L) {
output.WriteRawTag(24);
output.WriteInt64(Date);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (NickName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(NickName);
}
if (ChatMsg.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ChatMsg);
}
if (Date != 0L) {
output.WriteRawTag(24);
output.WriteInt64(Date);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (NickName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(NickName);
}
if (ChatMsg.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg);
}
if (Date != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(Date);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_ChatMsg_RESP other) {
if (other == null) {
return;
}
if (other.NickName.Length != 0) {
NickName = other.NickName;
}
if (other.ChatMsg.Length != 0) {
ChatMsg = other.ChatMsg;
}
if (other.Date != 0L) {
Date = other.Date;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
NickName = input.ReadString();
break;
}
case 18: {
ChatMsg = input.ReadString();
break;
}
case 24: {
Date = input.ReadInt64();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
NickName = input.ReadString();
break;
}
case 18: {
ChatMsg = input.ReadString();
break;
}
case 24: {
Date = input.ReadInt64();
break;
}
}
}
}
#endif
}
#endregion #endregion
} }

View File

@ -30,20 +30,25 @@ namespace AxibugProtobuf {
"b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY", "b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY",
"BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV", "BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV",
"Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh", "Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh",
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMq", "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"KwoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURfTE9HSU4Q0Q8q", "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq", "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB", "GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB",
"EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw", "VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy",
"ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD", "b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n",
"UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0", "aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi", "MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh",
"BnByb3RvMw==")); "dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv",
"Mw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null) new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg), global::AxibugProtobuf.Protobuf_ChatMsg.Parser, new[]{ "ChatMsg" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg_RESP), global::AxibugProtobuf.Protobuf_ChatMsg_RESP.Parser, new[]{ "NickName", "ChatMsg", "Date" }, null, null, null, null)
})); }));
} }
#endregion #endregion
@ -59,6 +64,10 @@ namespace AxibugProtobuf {
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP ///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001, [pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001,
/// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001,
} }
public enum ErrorCode { public enum ErrorCode {
@ -695,6 +704,440 @@ namespace AxibugProtobuf {
} }
/// <summary>
///聊天 上行
/// </summary>
public sealed partial class Protobuf_ChatMsg : pb::IMessage<Protobuf_ChatMsg>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_ChatMsg> _parser = new pb::MessageParser<Protobuf_ChatMsg>(() => new Protobuf_ChatMsg());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_ChatMsg> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufAuthReflection.Descriptor.MessageTypes[2]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg(Protobuf_ChatMsg other) : this() {
chatMsg_ = other.chatMsg_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg Clone() {
return new Protobuf_ChatMsg(this);
}
/// <summary>Field number for the "ChatMsg" field.</summary>
public const int ChatMsgFieldNumber = 1;
private string chatMsg_ = "";
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ChatMsg {
get { return chatMsg_; }
set {
chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_ChatMsg);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_ChatMsg other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (ChatMsg != other.ChatMsg) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (ChatMsg.Length != 0) hash ^= ChatMsg.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (ChatMsg.Length != 0) {
output.WriteRawTag(10);
output.WriteString(ChatMsg);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (ChatMsg.Length != 0) {
output.WriteRawTag(10);
output.WriteString(ChatMsg);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (ChatMsg.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_ChatMsg other) {
if (other == null) {
return;
}
if (other.ChatMsg.Length != 0) {
ChatMsg = other.ChatMsg;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
ChatMsg = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
ChatMsg = input.ReadString();
break;
}
}
}
}
#endif
}
/// <summary>
///聊天 下行
/// </summary>
public sealed partial class Protobuf_ChatMsg_RESP : pb::IMessage<Protobuf_ChatMsg_RESP>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_ChatMsg_RESP> _parser = new pb::MessageParser<Protobuf_ChatMsg_RESP>(() => new Protobuf_ChatMsg_RESP());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_ChatMsg_RESP> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufAuthReflection.Descriptor.MessageTypes[3]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP(Protobuf_ChatMsg_RESP other) : this() {
nickName_ = other.nickName_;
chatMsg_ = other.chatMsg_;
date_ = other.date_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_ChatMsg_RESP Clone() {
return new Protobuf_ChatMsg_RESP(this);
}
/// <summary>Field number for the "NickName" field.</summary>
public const int NickNameFieldNumber = 1;
private string nickName_ = "";
/// <summary>
///昵称
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string NickName {
get { return nickName_; }
set {
nickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "ChatMsg" field.</summary>
public const int ChatMsgFieldNumber = 2;
private string chatMsg_ = "";
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ChatMsg {
get { return chatMsg_; }
set {
chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "Date" field.</summary>
public const int DateFieldNumber = 3;
private long date_;
/// <summary>
///消息
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long Date {
get { return date_; }
set {
date_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_ChatMsg_RESP);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_ChatMsg_RESP other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (NickName != other.NickName) return false;
if (ChatMsg != other.ChatMsg) return false;
if (Date != other.Date) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (NickName.Length != 0) hash ^= NickName.GetHashCode();
if (ChatMsg.Length != 0) hash ^= ChatMsg.GetHashCode();
if (Date != 0L) hash ^= Date.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (NickName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(NickName);
}
if (ChatMsg.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ChatMsg);
}
if (Date != 0L) {
output.WriteRawTag(24);
output.WriteInt64(Date);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (NickName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(NickName);
}
if (ChatMsg.Length != 0) {
output.WriteRawTag(18);
output.WriteString(ChatMsg);
}
if (Date != 0L) {
output.WriteRawTag(24);
output.WriteInt64(Date);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (NickName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(NickName);
}
if (ChatMsg.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg);
}
if (Date != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(Date);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_ChatMsg_RESP other) {
if (other == null) {
return;
}
if (other.NickName.Length != 0) {
NickName = other.NickName;
}
if (other.ChatMsg.Length != 0) {
ChatMsg = other.ChatMsg;
}
if (other.Date != 0L) {
Date = other.Date;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
NickName = input.ReadString();
break;
}
case 18: {
ChatMsg = input.ReadString();
break;
}
case 24: {
Date = input.ReadInt64();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
NickName = input.ReadString();
break;
}
case 18: {
ChatMsg = input.ReadString();
break;
}
case 24: {
Date = input.ReadInt64();
break;
}
}
}
}
#endif
}
#endregion #endregion
} }

View File

@ -7,6 +7,8 @@ enum CommandID
CMD_DEFAUL = 0;//使 CMD_DEFAUL = 0;//使
CMD_LOGIN = 2001; // | Protobuf_Login | Protobuf_Login_RESP CMD_LOGIN = 2001; // | Protobuf_Login | Protobuf_Login_RESP
CMD_CHATMSG = 4001; // | Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
} }
enum ErrorCode enum ErrorCode
@ -56,3 +58,18 @@ message Protobuf_Login_RESP
string RegDate = 3;// string RegDate = 3;//
LoginResultStatus Status = 4;// [1][0] LoginResultStatus Status = 4;// [1][0]
} }
//
message Protobuf_ChatMsg
{
string ChatMsg = 1;//
}
//
message Protobuf_ChatMsg_RESP
{
string NickName = 1;//
string ChatMsg = 2;//
int64 Date = 3;//
}

View File

@ -10,7 +10,7 @@ while (true)
switch (Command) switch (Command)
{ {
case "list": case "list":
Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.ClientList.Count()); Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.GetOnlineClient());
break; break;
default: default:
Console.WriteLine("未知命令" + CommandStr); Console.WriteLine("未知命令" + CommandStr);

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServerCore.Common
{
public static class Helper
{
public static long GetNowTimeStamp()
{
return GetTimeStamp(DateTime.Now);
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static long GetTimeStamp(DateTime dt)
{
TimeSpan ts = dt - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds);
}
}
}

View File

@ -0,0 +1,23 @@
using AxibugProtobuf;
using ServerCore.Common;
using System.Net.Sockets;
namespace ServerCore
{
public class ChatManager
{
public void RecvPlayerChatMsg(Socket sk, byte[] reqData)
{
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
ServerManager.g_Log.Debug("收到新的登录请求");
Protobuf_ChatMsg msg = NetBase.DeSerizlize<Protobuf_ChatMsg>(reqData);
byte[] respData = NetBase.Serizlize(new Protobuf_ChatMsg_RESP()
{
ChatMsg = msg.ChatMsg,
NickName = _c.Account,
Date = Helper.GetNowTimeStamp()
});
ServerManager.g_ClientMgr.ClientSendALL((int)CommandID.CmdChatmsg, (int)ErrorCode.ErrorOk, respData);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Net.Sockets; using AxibugProtobuf;
using System.Net.Sockets;
using System.Timers; using System.Timers;
namespace ServerCore namespace ServerCore
@ -6,6 +7,7 @@ namespace ServerCore
public class ClientInfo public class ClientInfo
{ {
public long UID { get; set; } public long UID { get; set; }
public string Account { get; set; }
public Socket _socket { get; set; } public Socket _socket { get; set; }
public bool IsOffline { get; set; } = false; public bool IsOffline { get; set; } = false;
public DateTime LogOutDT { get; set; } public DateTime LogOutDT { get; set; }
@ -13,14 +15,14 @@ namespace ServerCore
public class ClientManager public class ClientManager
{ {
public List<ClientInfo> ClientList = new List<ClientInfo>(); private List<ClientInfo> ClientList = new List<ClientInfo>();
public Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>(); private Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>();
public Dictionary<long?, ClientInfo> _DictUIDClient = new Dictionary<long?, ClientInfo>(); private Dictionary<long?, ClientInfo> _DictUIDClient = new Dictionary<long?, ClientInfo>();
public long TestUIDSeed = 0; private long TestUIDSeed = 0;
private System.Timers.Timer _ClientCheckTimer; private System.Timers.Timer _ClientCheckTimer;
private long _RemoveOfflineCacheMin; private long _RemoveOfflineCacheMin;
public void Init(long ticktime,long RemoveOfflineCacheMin) public void Init(long ticktime, long RemoveOfflineCacheMin)
{ {
//换算成毫秒 //换算成毫秒
_RemoveOfflineCacheMin = RemoveOfflineCacheMin * 1000; _RemoveOfflineCacheMin = RemoveOfflineCacheMin * 1000;
@ -54,7 +56,7 @@ namespace ServerCore
//通用处理 //通用处理
#region clientlist #region clientlist
public ClientInfo JoinNewClient(Socket _socket) public ClientInfo JoinNewClient(Protobuf_Login data, Socket _socket)
{ {
//也许这个函数需加lock //也许这个函数需加lock
@ -62,7 +64,7 @@ namespace ServerCore
//如果连接还在 //如果连接还在
if (cinfo != null) if (cinfo != null)
{ {
cinfo.IsOffline = true; cinfo.IsOffline = false;
} }
else else
{ {
@ -70,7 +72,8 @@ namespace ServerCore
{ {
UID = GetNextUID(), UID = GetNextUID(),
_socket = _socket, _socket = _socket,
IsOffline = true, Account = data.Account,
IsOffline = false,
}; };
AddClient(cinfo); AddClient(cinfo);
} }
@ -85,7 +88,7 @@ namespace ServerCore
{ {
try try
{ {
Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID); Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID + " | " + clientInfo.Account);
lock (ClientList) lock (ClientList)
{ {
_DictUIDClient.Add(clientInfo.UID, clientInfo); _DictUIDClient.Add(clientInfo.UID, clientInfo);
@ -107,7 +110,7 @@ namespace ServerCore
{ {
lock (ClientList) lock (ClientList)
{ {
if(_DictUIDClient.ContainsKey(client.UID)) if (_DictUIDClient.ContainsKey(client.UID))
_DictUIDClient.Remove(client.UID); _DictUIDClient.Remove(client.UID);
if (_DictSocketClient.ContainsKey(client._socket)) if (_DictSocketClient.ContainsKey(client._socket))
@ -142,7 +145,7 @@ namespace ServerCore
if (!_DictSocketClient.ContainsKey(sk)) if (!_DictSocketClient.ContainsKey(sk))
return; return;
Console.WriteLine("标记玩家UID"+ _DictSocketClient[sk].UID+ "为离线"); Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线");
_DictSocketClient[sk].IsOffline = true; _DictSocketClient[sk].IsOffline = true;
_DictSocketClient[sk].LogOutDT = DateTime.Now; _DictSocketClient[sk].LogOutDT = DateTime.Now;
} }
@ -157,6 +160,10 @@ namespace ServerCore
#endregion #endregion
public void ClientSendALL(int CMDID, int ERRCODE, byte[] data)
{
ClientSend(ClientList,CMDID, ERRCODE, data);
}
/// <summary> /// <summary>
/// 给一组用户发送数据 /// 给一组用户发送数据
@ -194,5 +201,10 @@ namespace ServerCore
return; return;
ServerManager.g_SocketMgr.SendToSocket(_c._socket, CMDID, ERRCODE, data); ServerManager.g_SocketMgr.SendToSocket(_c._socket, CMDID, ERRCODE, data);
} }
public int GetOnlineClient()
{
return ClientList.Where(w => !w.IsOffline).Count();
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace ServerCore
{ {
ServerManager.g_Log.Debug("收到新的登录请求"); ServerManager.g_Log.Debug("收到新的登录请求");
Protobuf_Login msg = NetBase.DeSerizlize<Protobuf_Login>(reqData); Protobuf_Login msg = NetBase.DeSerizlize<Protobuf_Login>(reqData);
ClientInfo cinfo = ServerManager.g_ClientMgr.JoinNewClient(_socket); ClientInfo cinfo = ServerManager.g_ClientMgr.JoinNewClient(msg,_socket);
byte[] respData = NetBase.Serizlize(new Protobuf_Login_RESP() byte[] respData = NetBase.Serizlize(new Protobuf_Login_RESP()
{ {

View File

@ -7,6 +7,7 @@ namespace ServerCore
public static ClientManager g_ClientMgr; public static ClientManager g_ClientMgr;
public static LogManager g_Log; public static LogManager g_Log;
public static LoginManager g_Login; public static LoginManager g_Login;
public static ChatManager g_Chat;
public static IOCPNetWork g_SocketMgr; public static IOCPNetWork g_SocketMgr;
public static void InitServer(int port) public static void InitServer(int port)
@ -14,6 +15,7 @@ namespace ServerCore
g_ClientMgr = new ClientManager(); g_ClientMgr = new ClientManager();
g_Log = new LogManager(); g_Log = new LogManager();
g_Login = new LoginManager(); g_Login = new LoginManager();
g_Chat = new ChatManager();
g_SocketMgr = new IOCPNetWork(1024, 1024); g_SocketMgr = new IOCPNetWork(1024, 1024);
g_SocketMgr.Init(); g_SocketMgr.Init();
g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port)); g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port));

View File

@ -47,7 +47,8 @@ namespace ServerCore
{ {
switch ((CommandID)CMDID) switch ((CommandID)CMDID)
{ {
case CommandID.CmdLogin:ServerManager.g_Login.UserLogin(sk, data); break; case CommandID.CmdLogin: ServerManager.g_Login.UserLogin(sk, data); break;
case CommandID.CmdChatmsg: ServerManager.g_Chat.RecvPlayerChatMsg(sk, data);break;
} }
} }
catch (Exception ex) catch (Exception ex)