Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

refactor: refactor the server according to the new proto files #28

Merged
merged 3 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions communication/Proto/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

namespace Communication.Proto
{
/// <summary>
/// 游戏信息类型。此处的类型完全根据proto文件的信息决定,实际上可以自行删减——把所有的"MessageToxx"类的名称都列举在这里就可以了
/// </summary>
public enum PacketType
{
MessageToClient = 0, // 全局信息
MessageToServer = 0,
MessageToOneClient = 1, // 单人信息
MessageToServer = 2,
// 以下的枚举全部由原来的(指THUAI4和THUAI5的上一个版本)的MessageToClient拆分而来,一方面降低了广播带来的信息耦合程度,另一方面也增强了代码的可读性
MessageToInitialize = 2,
MessageToOperate = 3,
MessageToRefresh = 4,
}

/// <summary>
/// 信息的通用接口,包含信息类型和内容
/// </summary>
public interface IGameMessage
{
PacketType PacketType { get; set; }
IMessage Content { get; set; } // Protobuf的通用接口
IMessage Content { get; set; }
}

/// <summary>
Expand All @@ -39,18 +47,8 @@ public void Deserialize(byte[] bytes)

type = (PacketType)br.ReadInt32();
string typename = null;
switch (type)
{
case PacketType.MessageToClient:
typename = "Communication.Proto.MessageToClient";
break;
case PacketType.MessageToOneClient:
typename = "Communication.Proto.MessageToOneClient";
break;
case PacketType.MessageToServer:
typename = "Communication.Proto.MessageToServer";
break;
}
// 由于枚举值增多,这里将“枚举转类型名称”改写成一种更加简洁的方式
typename = "Communication.Proto." + Enum.GetName(typeof(PacketType), type);

try
{
Expand Down
3,790 changes: 2,415 additions & 1,375 deletions communication/Proto/Message2Clients.cs

Large diffs are not rendered by default.

84 changes: 23 additions & 61 deletions communication/Proto/Message2Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@ static Message2ServerReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChRNZXNzYWdlMlNlcnZlci5wcm90bxIIUHJvdG9idWYaEU1lc3NhZ2VUeXBl",
"LnByb3RvGhVNZXNzYWdlMkNsaWVudHMucHJvdG8i2QIKD01lc3NhZ2VUb1Nl",
"LnByb3RvGhVNZXNzYWdlMkNsaWVudHMucHJvdG8irQIKD01lc3NhZ2VUb1Nl",
"cnZlchIqCgttZXNzYWdlVHlwZRgBIAEoDjIVLlByb3RvYnVmLk1lc3NhZ2VU",
"eXBlEhAKCHBsYXllcklEGAIgASgDEg4KBnRlYW1JRBgDIAEoAxIkCghwcm9w",
"VHlwZRgEIAEoDjISLlByb3RvYnVmLlByb3BUeXBlEhoKEnRpbWVJbk1pbGxp",
"c2Vjb25kcxgFIAEoBRINCgVhbmdsZRgGIAEoARISCgpUb1BsYXllcklEGAcg",
"ASgDEg8KB21lc3NhZ2UYCCABKAkSKgoGcFNraWxsGAkgASgOMhouUHJvdG9i",
"dWYuUGFzc2l2ZVNraWxsVHlwZRIqCgdhU2tpbGwxGAogASgOMhkuUHJvdG9i",
"dWYuQWN0aXZlU2tpbGxUeXBlEioKB2FTa2lsbDIYCyABKA4yGS5Qcm90b2J1",
"Zi5BY3RpdmVTa2lsbFR5cGVCFqoCE0NvbW11bmljYXRpb24uUHJvdG9iBnBy",
"b3RvMw=="));
"dWYuQWN0aXZlU2tpbGxUeXBlQhaqAhNDb21tdW5pY2F0aW9uLlByb3RvYgZw",
"cm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Communication.Proto.MessageTypeReflection.Descriptor, global::Communication.Proto.Message2ClientsReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Communication.Proto.MessageToServer), global::Communication.Proto.MessageToServer.Parser, new[]{ "MessageType", "PlayerID", "TeamID", "PropType", "TimeInMilliseconds", "Angle", "ToPlayerID", "Message", "PSkill", "ASkill1", "ASkill2" }, null, null, null, null)
new pbr::GeneratedClrTypeInfo(typeof(global::Communication.Proto.MessageToServer), global::Communication.Proto.MessageToServer.Parser, new[]{ "MessageType", "PlayerID", "TeamID", "PropType", "TimeInMilliseconds", "Angle", "ToPlayerID", "Message", "PSkill", "ASkill1" }, null, null, null, null)
}));
}
#endregion
Expand Down Expand Up @@ -89,7 +88,6 @@ public MessageToServer(MessageToServer other) : this() {
message_ = other.message_;
pSkill_ = other.pSkill_;
aSkill1_ = other.aSkill1_;
aSkill2_ = other.aSkill2_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

Expand Down Expand Up @@ -143,7 +141,7 @@ public long TeamID {

/// <summary>Field number for the "propType" field.</summary>
public const int PropTypeFieldNumber = 4;
private global::Communication.Proto.PropType propType_ = global::Communication.Proto.PropType.Null;
private global::Communication.Proto.PropType propType_ = global::Communication.Proto.PropType.NullPropType;
/// <summary>
///messageType为Pick时要捡起的道具类型
/// </summary>
Expand Down Expand Up @@ -218,9 +216,9 @@ public string Message {

/// <summary>Field number for the "pSkill" field.</summary>
public const int PSkillFieldNumber = 9;
private global::Communication.Proto.PassiveSkillType pSkill_ = global::Communication.Proto.PassiveSkillType.Pskill0;
private global::Communication.Proto.PassiveSkillType pSkill_ = global::Communication.Proto.PassiveSkillType.NullPassiveSkillType;
/// <summary>
///AddPlayer时添加的被动技能,下面是添加的两个主动技能
///AddPlayer时添加的被动技能,下面是添加的一个主动技能
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
Expand All @@ -233,7 +231,7 @@ public string Message {

/// <summary>Field number for the "aSkill1" field.</summary>
public const int ASkill1FieldNumber = 10;
private global::Communication.Proto.ActiveSkillType aSkill1_ = global::Communication.Proto.ActiveSkillType.Askill0;
private global::Communication.Proto.ActiveSkillType aSkill1_ = global::Communication.Proto.ActiveSkillType.NullActiveSkillType;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::Communication.Proto.ActiveSkillType ASkill1 {
Expand All @@ -243,18 +241,6 @@ public string Message {
}
}

/// <summary>Field number for the "aSkill2" field.</summary>
public const int ASkill2FieldNumber = 11;
private global::Communication.Proto.ActiveSkillType aSkill2_ = global::Communication.Proto.ActiveSkillType.Askill0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::Communication.Proto.ActiveSkillType ASkill2 {
get { return aSkill2_; }
set {
aSkill2_ = value;
}
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
Expand All @@ -280,7 +266,6 @@ public bool Equals(MessageToServer other) {
if (Message != other.Message) return false;
if (PSkill != other.PSkill) return false;
if (ASkill1 != other.ASkill1) return false;
if (ASkill2 != other.ASkill2) return false;
return Equals(_unknownFields, other._unknownFields);
}

Expand All @@ -291,14 +276,13 @@ public override int GetHashCode() {
if (MessageType != global::Communication.Proto.MessageType.AddPlayer) hash ^= MessageType.GetHashCode();
if (PlayerID != 0L) hash ^= PlayerID.GetHashCode();
if (TeamID != 0L) hash ^= TeamID.GetHashCode();
if (PropType != global::Communication.Proto.PropType.Null) hash ^= PropType.GetHashCode();
if (PropType != global::Communication.Proto.PropType.NullPropType) hash ^= PropType.GetHashCode();
if (TimeInMilliseconds != 0) hash ^= TimeInMilliseconds.GetHashCode();
if (Angle != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Angle);
if (ToPlayerID != 0L) hash ^= ToPlayerID.GetHashCode();
if (Message.Length != 0) hash ^= Message.GetHashCode();
if (PSkill != global::Communication.Proto.PassiveSkillType.Pskill0) hash ^= PSkill.GetHashCode();
if (ASkill1 != global::Communication.Proto.ActiveSkillType.Askill0) hash ^= ASkill1.GetHashCode();
if (ASkill2 != global::Communication.Proto.ActiveSkillType.Askill0) hash ^= ASkill2.GetHashCode();
if (PSkill != global::Communication.Proto.PassiveSkillType.NullPassiveSkillType) hash ^= PSkill.GetHashCode();
if (ASkill1 != global::Communication.Proto.ActiveSkillType.NullActiveSkillType) hash ^= ASkill1.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand Down Expand Up @@ -329,7 +313,7 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(24);
output.WriteInt64(TeamID);
}
if (PropType != global::Communication.Proto.PropType.Null) {
if (PropType != global::Communication.Proto.PropType.NullPropType) {
output.WriteRawTag(32);
output.WriteEnum((int) PropType);
}
Expand All @@ -349,18 +333,14 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(66);
output.WriteString(Message);
}
if (PSkill != global::Communication.Proto.PassiveSkillType.Pskill0) {
if (PSkill != global::Communication.Proto.PassiveSkillType.NullPassiveSkillType) {
output.WriteRawTag(72);
output.WriteEnum((int) PSkill);
}
if (ASkill1 != global::Communication.Proto.ActiveSkillType.Askill0) {
if (ASkill1 != global::Communication.Proto.ActiveSkillType.NullActiveSkillType) {
output.WriteRawTag(80);
output.WriteEnum((int) ASkill1);
}
if (ASkill2 != global::Communication.Proto.ActiveSkillType.Askill0) {
output.WriteRawTag(88);
output.WriteEnum((int) ASkill2);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
Expand All @@ -383,7 +363,7 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(24);
output.WriteInt64(TeamID);
}
if (PropType != global::Communication.Proto.PropType.Null) {
if (PropType != global::Communication.Proto.PropType.NullPropType) {
output.WriteRawTag(32);
output.WriteEnum((int) PropType);
}
Expand All @@ -403,18 +383,14 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(66);
output.WriteString(Message);
}
if (PSkill != global::Communication.Proto.PassiveSkillType.Pskill0) {
if (PSkill != global::Communication.Proto.PassiveSkillType.NullPassiveSkillType) {
output.WriteRawTag(72);
output.WriteEnum((int) PSkill);
}
if (ASkill1 != global::Communication.Proto.ActiveSkillType.Askill0) {
if (ASkill1 != global::Communication.Proto.ActiveSkillType.NullActiveSkillType) {
output.WriteRawTag(80);
output.WriteEnum((int) ASkill1);
}
if (ASkill2 != global::Communication.Proto.ActiveSkillType.Askill0) {
output.WriteRawTag(88);
output.WriteEnum((int) ASkill2);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
Expand All @@ -434,7 +410,7 @@ public int CalculateSize() {
if (TeamID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(TeamID);
}
if (PropType != global::Communication.Proto.PropType.Null) {
if (PropType != global::Communication.Proto.PropType.NullPropType) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) PropType);
}
if (TimeInMilliseconds != 0) {
Expand All @@ -449,15 +425,12 @@ public int CalculateSize() {
if (Message.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
}
if (PSkill != global::Communication.Proto.PassiveSkillType.Pskill0) {
if (PSkill != global::Communication.Proto.PassiveSkillType.NullPassiveSkillType) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) PSkill);
}
if (ASkill1 != global::Communication.Proto.ActiveSkillType.Askill0) {
if (ASkill1 != global::Communication.Proto.ActiveSkillType.NullActiveSkillType) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) ASkill1);
}
if (ASkill2 != global::Communication.Proto.ActiveSkillType.Askill0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) ASkill2);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
Expand All @@ -479,7 +452,7 @@ public void MergeFrom(MessageToServer other) {
if (other.TeamID != 0L) {
TeamID = other.TeamID;
}
if (other.PropType != global::Communication.Proto.PropType.Null) {
if (other.PropType != global::Communication.Proto.PropType.NullPropType) {
PropType = other.PropType;
}
if (other.TimeInMilliseconds != 0) {
Expand All @@ -494,15 +467,12 @@ public void MergeFrom(MessageToServer other) {
if (other.Message.Length != 0) {
Message = other.Message;
}
if (other.PSkill != global::Communication.Proto.PassiveSkillType.Pskill0) {
if (other.PSkill != global::Communication.Proto.PassiveSkillType.NullPassiveSkillType) {
PSkill = other.PSkill;
}
if (other.ASkill1 != global::Communication.Proto.ActiveSkillType.Askill0) {
if (other.ASkill1 != global::Communication.Proto.ActiveSkillType.NullActiveSkillType) {
ASkill1 = other.ASkill1;
}
if (other.ASkill2 != global::Communication.Proto.ActiveSkillType.Askill0) {
ASkill2 = other.ASkill2;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}

Expand Down Expand Up @@ -558,10 +528,6 @@ public void MergeFrom(pb::CodedInputStream input) {
ASkill1 = (global::Communication.Proto.ActiveSkillType) input.ReadEnum();
break;
}
case 88: {
ASkill2 = (global::Communication.Proto.ActiveSkillType) input.ReadEnum();
break;
}
}
}
#endif
Expand Down Expand Up @@ -617,10 +583,6 @@ public void MergeFrom(pb::CodedInputStream input) {
ASkill1 = (global::Communication.Proto.ActiveSkillType) input.ReadEnum();
break;
}
case 88: {
ASkill2 = (global::Communication.Proto.ActiveSkillType) input.ReadEnum();
break;
}
}
}
}
Expand Down
Loading