feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) + game logic (GameFix/GameDAL/ServerData) + network layer (NetWorkMessage) + data layer (ObjectModel) + utilities (MrWu/Core/Config/CloudAPI/dll) + adapters (zyxAdapter/base) .NET 8.0 C# solution, 16 projects, 958 source files
This commit is contained in:
96
ServerCore/NetWork/AChannel.cs
Normal file
96
ServerCore/NetWork/AChannel.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Server.Net
|
||||
{
|
||||
public enum ChannelType
|
||||
{
|
||||
Connect,
|
||||
Accept,
|
||||
}
|
||||
|
||||
public struct Packet
|
||||
{
|
||||
public const int MinPacketSize = MessageIndex + OpcodeLength;
|
||||
public const int ActorIdLength = 3;
|
||||
public const int OpcodeLength = 4;
|
||||
public const int MessageIndex = ActorIdLength + ActorIdLength;
|
||||
|
||||
public ushort Opcode;
|
||||
public MemoryStream MemoryStream;
|
||||
}
|
||||
|
||||
public struct RouterPacket
|
||||
{
|
||||
/// <summary>
|
||||
/// 总长度
|
||||
/// </summary>
|
||||
public const int TotalLength = 4;
|
||||
|
||||
/// <summary>
|
||||
/// 路由包长度
|
||||
/// </summary>
|
||||
public const int RouterPacketLength = 4;
|
||||
|
||||
/// <summary>
|
||||
/// 路由包长度索引
|
||||
/// </summary>
|
||||
public const int RouterPacketLengthIndex = TotalLength;
|
||||
|
||||
/// <summary>
|
||||
/// 路由包类型
|
||||
/// </summary>
|
||||
public const int RouterPacketOpcode = 4;
|
||||
|
||||
public const int RouterPacketOpcodeIndex = TotalLength + RouterPacketLength;
|
||||
|
||||
public const int RouterPacketBodyIndex = TotalLength + RouterPacketLength + RouterPacketOpcode;
|
||||
|
||||
/// <summary>
|
||||
/// 路由包数据的最小长度
|
||||
/// </summary>
|
||||
public const int RouterPacketMinLength = TotalLength + RouterPacketLength + RouterPacketOpcode;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端包长度
|
||||
/// </summary>
|
||||
public const int ClientPacketLength = 4;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端包类型
|
||||
/// </summary>
|
||||
public const int ClientPacketOpcode = 4;
|
||||
}
|
||||
|
||||
public abstract class AChannel : IDisposable
|
||||
{
|
||||
public long Id;
|
||||
|
||||
public ChannelType ChannelType { get; protected set; }
|
||||
|
||||
private IPEndPoint remoteAddress;
|
||||
|
||||
public IPEndPoint RemoteAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.remoteAddress;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.remoteAddress = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Id == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user