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;
ClientManager.Init("127.0.0.1", 23846);
App.Init("127.0.0.1", 23846);
//注册
App.chat.OnChatMsg += OnChatMsg;
while (true)
{
string CommandStr = Console.ReadLine();
string Command = "";
Command = ((CommandStr.IndexOf(" ") <= 0) ? CommandStr : CommandStr.Substring(0, CommandStr.IndexOf(" ")));
string[] CmdArr = CommandStr.Split(' ');
switch (Command)
{
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;
default:
Console.WriteLine("未知命令" + CommandStr);
break;
}
}
void OnChatMsg(string str1, string str2)
{
Console.WriteLine($"[Chat]{str1}:{str2}");
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ClientCore
{
public class StaticComm
public class App
{
public static string TokenStr;
public static long RID = -1;
@ -14,5 +14,16 @@ namespace ClientCore
public static int Port;
public static NetworkHelper networkHelper;
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 void Login()
public void Login(string Account)
{
Protobuf_Login msg = new Protobuf_Login()
{
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)
{
case CommandID.CmdLogin: break;
case CommandID.CmdChatmsg: App.chat.RecvChatMsg(data); break;
}
}
catch (Exception ex)

View File

@ -30,20 +30,25 @@ namespace AxibugProtobuf {
"b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY",
"BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV",
"Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh",
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMq",
"KwoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURfTE9HSU4Q0Q8q",
"KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq",
"PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB",
"EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw",
"ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD",
"UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi",
"BnByb3RvMw=="));
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB",
"VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy",
"b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n",
"aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG",
"MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh",
"dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv",
"Mw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
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(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
@ -59,6 +64,10 @@ namespace AxibugProtobuf {
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001,
/// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001,
}
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
}

View File

@ -30,20 +30,25 @@ namespace AxibugProtobuf {
"b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY",
"BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV",
"Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh",
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMq",
"KwoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURfTE9HSU4Q0Q8q",
"KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq",
"PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB",
"EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw",
"ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD",
"UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi",
"BnByb3RvMw=="));
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB",
"VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy",
"b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n",
"aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG",
"MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh",
"dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv",
"Mw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
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(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
@ -59,6 +64,10 @@ namespace AxibugProtobuf {
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001,
/// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001,
}
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
}

View File

@ -7,6 +7,8 @@ enum CommandID
CMD_DEFAUL = 0;//使
CMD_LOGIN = 2001; // | Protobuf_Login | Protobuf_Login_RESP
CMD_CHATMSG = 4001; // | Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
}
enum ErrorCode
@ -55,4 +57,19 @@ message Protobuf_Login_RESP
string LastLoginDate = 2;//
string RegDate = 3;//
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)
{
case "list":
Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.ClientList.Count());
Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.GetOnlineClient());
break;
default:
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;
namespace ServerCore
@ -6,6 +7,7 @@ namespace ServerCore
public class ClientInfo
{
public long UID { get; set; }
public string Account { get; set; }
public Socket _socket { get; set; }
public bool IsOffline { get; set; } = false;
public DateTime LogOutDT { get; set; }
@ -13,14 +15,14 @@ namespace ServerCore
public class ClientManager
{
public List<ClientInfo> ClientList = new List<ClientInfo>();
public Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>();
public Dictionary<long?, ClientInfo> _DictUIDClient = new Dictionary<long?, ClientInfo>();
public long TestUIDSeed = 0;
private List<ClientInfo> ClientList = new List<ClientInfo>();
private Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>();
private Dictionary<long?, ClientInfo> _DictUIDClient = new Dictionary<long?, ClientInfo>();
private long TestUIDSeed = 0;
private System.Timers.Timer _ClientCheckTimer;
private long _RemoveOfflineCacheMin;
public void Init(long ticktime,long RemoveOfflineCacheMin)
public void Init(long ticktime, long RemoveOfflineCacheMin)
{
//换算成毫秒
_RemoveOfflineCacheMin = RemoveOfflineCacheMin * 1000;
@ -35,7 +37,7 @@ namespace ServerCore
{
return ++TestUIDSeed;
}
private void ClientCheckClearOffline_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin);
@ -54,7 +56,7 @@ namespace ServerCore
//通用处理
#region clientlist
public ClientInfo JoinNewClient(Socket _socket)
public ClientInfo JoinNewClient(Protobuf_Login data, Socket _socket)
{
//也许这个函数需加lock
@ -62,7 +64,7 @@ namespace ServerCore
//如果连接还在
if (cinfo != null)
{
cinfo.IsOffline = true;
cinfo.IsOffline = false;
}
else
{
@ -70,7 +72,8 @@ namespace ServerCore
{
UID = GetNextUID(),
_socket = _socket,
IsOffline = true,
Account = data.Account,
IsOffline = false,
};
AddClient(cinfo);
}
@ -85,7 +88,7 @@ namespace ServerCore
{
try
{
Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID);
Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID + " | " + clientInfo.Account);
lock (ClientList)
{
_DictUIDClient.Add(clientInfo.UID, clientInfo);
@ -98,7 +101,7 @@ namespace ServerCore
ex.ToString();
}
}
/// <summary>
/// 清理连接
/// </summary>
@ -107,12 +110,12 @@ namespace ServerCore
{
lock (ClientList)
{
if(_DictUIDClient.ContainsKey(client.UID))
if (_DictUIDClient.ContainsKey(client.UID))
_DictUIDClient.Remove(client.UID);
if (_DictSocketClient.ContainsKey(client._socket))
_DictSocketClient.Remove(client._socket);
ClientList.Remove(client);
}
}
@ -142,7 +145,7 @@ namespace ServerCore
if (!_DictSocketClient.ContainsKey(sk))
return;
Console.WriteLine("标记玩家UID"+ _DictSocketClient[sk].UID+ "为离线");
Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线");
_DictSocketClient[sk].IsOffline = true;
_DictSocketClient[sk].LogOutDT = DateTime.Now;
}
@ -157,6 +160,10 @@ namespace ServerCore
#endregion
public void ClientSendALL(int CMDID, int ERRCODE, byte[] data)
{
ClientSend(ClientList,CMDID, ERRCODE, data);
}
/// <summary>
/// 给一组用户发送数据
@ -194,5 +201,10 @@ namespace ServerCore
return;
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("收到新的登录请求");
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()
{

View File

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

View File

@ -47,7 +47,8 @@ namespace ServerCore
{
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)