mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-12-05 08:09:03 +00:00
添加实体类
This commit is contained in:
parent
3cfe9ceda2
commit
52c589aa3d
@ -5,10 +5,19 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ApplicationIcon>logo.ico</ApplicationIcon>
|
||||
<PackageIcon>logo.ico</PackageIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\Entity\" />
|
||||
<Content Include="logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="logo.ico">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
41
Main.cs
41
Main.cs
@ -11,15 +11,17 @@ using FunGameServer.Utils;
|
||||
bool Running = true;
|
||||
Socket? ServerSocket = null;
|
||||
|
||||
string host = Config.SERVER_IPADRESS;
|
||||
string hostname = Config.SERVER_NAME;
|
||||
int port = Config.SERVER_PORT;
|
||||
|
||||
Console.Title = Config.CONSOLE_TITLE;
|
||||
|
||||
try
|
||||
{
|
||||
Task t = Task.Factory.StartNew(() =>
|
||||
{
|
||||
// 创建IP地址终结点对象
|
||||
IPEndPoint ip = new(IPAddress.Parse(host), port);
|
||||
IPEndPoint ip = new(IPAddress.Any, port);
|
||||
|
||||
// 创建TCP Socket对象并绑定终结点
|
||||
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
@ -27,7 +29,7 @@ try
|
||||
|
||||
// 开始监听连接
|
||||
ServerSocket.Listen(Config.MAX_PLAYERS);
|
||||
Console.WriteLine("服务器启动成功,正在监听 . . .");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "服务器启动成功,正在监听 . . .");
|
||||
|
||||
while (Running)
|
||||
{
|
||||
@ -37,9 +39,9 @@ try
|
||||
socket = ServerSocket.Accept();
|
||||
IPEndPoint? clientIP = (IPEndPoint?)socket.RemoteEndPoint;
|
||||
if (clientIP != null)
|
||||
Console.WriteLine("客户端" + clientIP.ToString() + "连接 . . .");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "客户端" + clientIP.ToString() + "连接 . . .");
|
||||
else
|
||||
Console.WriteLine("未知地点客户端连接 . . .");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "未知地点客户端连接 . . .");
|
||||
if (Read(socket) && Send(socket))
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
@ -47,13 +49,13 @@ try
|
||||
});
|
||||
else
|
||||
if (clientIP != null)
|
||||
Console.WriteLine("客户端" + clientIP.ToString() + "连接失败。");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "客户端" + clientIP.ToString() + "连接失败。");
|
||||
else
|
||||
Console.WriteLine("客户端连接失败。");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "客户端连接失败。");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("ERROR: 客户端断开连接!\n" + e.StackTrace);
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "ERROR: 客户端断开连接!\n" + e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +88,7 @@ finally
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("服务器已关闭,按任意键退出程序。");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "服务器已关闭,按任意键退出程序。");
|
||||
Console.ReadKey();
|
||||
|
||||
|
||||
@ -98,27 +100,34 @@ bool Read(Socket socket)
|
||||
if (length > 0)
|
||||
{
|
||||
string msg = Config.DEFAULT_ENCODING.GetString(buffer, 0, length);
|
||||
Console.WriteLine("收到来自:客户端(玩家ID) -> " + msg);
|
||||
return true;
|
||||
string typestring = SocketHelper.GetTypeString(SocketHelper.GetType(msg));
|
||||
msg = SocketHelper.GetMessage(msg);
|
||||
if (typestring != SocketEnums.TYPE_UNKNOWN)
|
||||
{
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "[ 客户端(" + typestring + ")] -> " + msg);
|
||||
return true;
|
||||
}
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "客户端发送了不符合FunGame规定的字符,拒绝连接。");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
Console.WriteLine("客户端没有回应。");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "客户端没有回应。");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Send(Socket socket)
|
||||
{
|
||||
// 发送消息给客户端
|
||||
string msg = ">> 已连接至服务器 -> [ " + host + " ] 连接成功";
|
||||
string msg = ">> 已连接至服务器 -> [ " + hostname + " ] 连接成功";
|
||||
byte[] buffer = new byte[2048];
|
||||
buffer = Config.DEFAULT_ENCODING.GetBytes(SocketHelper.MakeMessage((int)SocketEnums.SendType.CheckLogin, msg));
|
||||
buffer = Config.DEFAULT_ENCODING.GetBytes(SocketHelper.MakeMessage((int)SocketEnums.Type.CheckLogin, msg));
|
||||
if (socket.Send(buffer) > 0)
|
||||
{
|
||||
Console.WriteLine("发送给:客户端 <- " + msg);
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "[ 客户端 ] <- " + msg);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
Console.WriteLine("无法传输数据,与客户端的连接可能丢失。");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "无法传输数据,与客户端的连接可能丢失。");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -14,10 +14,11 @@ namespace FunGameServer.Models.Config
|
||||
public static int MAX_PLAYERS = 16; // 最多接受连接的玩家数量
|
||||
public static int ONLINE_PLAYERS = 0; // 已连接的玩家数量
|
||||
public static int CONNECTING_PLAYERS = 0; // 正在连接的玩家数量
|
||||
public static string SERVER_IPADRESS = "127.0.0.1"; // 默认IP地址
|
||||
public static string SERVER_NAME = "米粒的糖果屋"; // 服务器名称
|
||||
public static int SERVER_PORT = 22222; // 默认端口
|
||||
public static Encoding DEFAULT_ENCODING = Encoding.UTF8; // 默认传输字符集
|
||||
public static int MAX_CONNECTFAILED = 5; // 最大连接失败次数
|
||||
public const string CONSOLE_TITLE = "FunGame Server";
|
||||
|
||||
/// <summary>
|
||||
/// string: 玩家标识ID
|
||||
|
||||
@ -8,7 +8,7 @@ namespace FunGameServer.Models.Config
|
||||
{
|
||||
public static class SocketEnums
|
||||
{
|
||||
public enum SendType
|
||||
public enum Type
|
||||
{
|
||||
GetNotice = 1,
|
||||
Login = 2,
|
||||
@ -17,19 +17,11 @@ namespace FunGameServer.Models.Config
|
||||
HeartBeat = 5
|
||||
}
|
||||
|
||||
public enum ReadType
|
||||
{
|
||||
GetNotice = 1,
|
||||
Login = 2,
|
||||
CheckLogin = 3,
|
||||
Logout = 4,
|
||||
HeartBeat = 5
|
||||
}
|
||||
|
||||
public static string SENDTYPE_GetNotice = "GetNotice";
|
||||
public static string SENDTYPE_Login = "Login";
|
||||
public static string SENDTYPE_CheckLogin = "CheckLogin";
|
||||
public static string SENDTYPE_Logout = "Logout";
|
||||
public static string SENDTYPE_HeartBeat = "HeartBeat";
|
||||
public const string TYPE_UNKNOWN = "Unknown Type";
|
||||
public const string TYPE_GetNotice = "GetNotice";
|
||||
public const string TYPE_Login = "Login";
|
||||
public const string TYPE_CheckLogin = "CheckLogin";
|
||||
public const string TYPE_Logout = "Logout";
|
||||
public const string TYPE_HeartBeat = "HeartBeat";
|
||||
}
|
||||
}
|
||||
|
||||
18
Models/Entity/ActiveItem.cs
Normal file
18
Models/Entity/ActiveItem.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class ActiveItem : Item
|
||||
{
|
||||
public ActiveSkill? Skill { get; set; } = null;
|
||||
|
||||
public ActiveItem()
|
||||
{
|
||||
Active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Models/Entity/ActiveSkill.cs
Normal file
29
Models/Entity/ActiveSkill.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class ActiveSkill : Skill
|
||||
{
|
||||
public decimal MP { get; set; } = 0;
|
||||
public decimal EP { get; set; } = 0;
|
||||
public decimal Reference1 { get; set; } = 0;
|
||||
public decimal Reference2 { get; set; } = 0;
|
||||
public decimal Reference3 { get; set; } = 0;
|
||||
public decimal Reference4 { get; set; } = 0;
|
||||
public decimal Reference5 { get; set; } = 0;
|
||||
public decimal Reference6 { get; set; } = 0;
|
||||
public decimal Reference7 { get; set; } = 0;
|
||||
public decimal Reference8 { get; set; } = 0;
|
||||
public decimal Reference9 { get; set; } = 0;
|
||||
public decimal Reference10 { get; set; } = 0;
|
||||
|
||||
public ActiveSkill()
|
||||
{
|
||||
Active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Models/Entity/Character.cs
Normal file
42
Models/Entity/Character.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class Character
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string FirstName { get; set; } = "";
|
||||
public User? User { get; set; } = null;
|
||||
public CharacterStatistics? Statistics { get; set; } = null;
|
||||
public int Level { get; set; } = 1;
|
||||
public decimal EXP { get; set; }
|
||||
public decimal HP { get; set; }
|
||||
public decimal MP { get; set; }
|
||||
public decimal EP { get; set; }
|
||||
public decimal ATK { get; set; }
|
||||
public decimal DEF { get; set; }
|
||||
public decimal PhysicalReduction { get; set; }
|
||||
public decimal MDF { get; set; }
|
||||
public decimal HPRecovery { get; set; } = 0;
|
||||
public decimal MPRecovery { get; set; } = 0;
|
||||
public decimal EPRecovery { get; set; } = 0;
|
||||
public decimal SPD { get; set; }
|
||||
public decimal ATR { get; set; }
|
||||
public decimal CritRate { get; set; } = 0.05M;
|
||||
public decimal CritDMG { get; set; } = 1.25M;
|
||||
public decimal EvadeRate { get; set; } = 0.05M;
|
||||
public Hashtable? Skills { get; set; } = new Hashtable();
|
||||
public Hashtable? Items { get; set; } = new Hashtable();
|
||||
|
||||
public Character()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Models/Entity/CharacterStatistics.cs
Normal file
34
Models/Entity/CharacterStatistics.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class CharacterStatistics
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Character? Character { get; set; } = null;
|
||||
public Hashtable? DamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? PhysicalDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? MagicDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RealDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgLiveRoundStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageRoundStats { get; set; } = new Hashtable();
|
||||
public Hashtable? KillStats { get; set; } = new Hashtable();
|
||||
public Hashtable? DeathStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AssistStats { get; set; } = new Hashtable();
|
||||
public Hashtable? Plays { get; set; } = new Hashtable();
|
||||
public Hashtable? Wins { get; set; } = new Hashtable();
|
||||
public Hashtable? Loses { get; set; } = new Hashtable();
|
||||
public Hashtable? Winrates { get; set; } = new Hashtable();
|
||||
|
||||
public CharacterStatistics()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Models/Entity/GameStatistics.cs
Normal file
35
Models/Entity/GameStatistics.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class GameStatistics
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Room? Room { get; set; } = null;
|
||||
public string? GameRecord { get; set; } = null;
|
||||
public string? RunTime { get; set; } = null;
|
||||
public Hashtable? DamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? PhysicalDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? MagicDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RealDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? KillStats { get; set; } = new Hashtable();
|
||||
public Hashtable? KillDetailStats { get; set; } = new Hashtable();
|
||||
public Hashtable? DeathStats { get; set; } = new Hashtable();
|
||||
public Hashtable? DeathDetailStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AssistStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RatingStats { get; set; } = new Hashtable();
|
||||
public Hashtable? EloStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RankStats { get; set; } = new Hashtable();
|
||||
|
||||
public GameStatistics()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Models/Entity/Item.cs
Normal file
19
Models/Entity/Item.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public abstract class Item
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Describe { get; set; } = "";
|
||||
public decimal Price { get; set; }
|
||||
public char Key { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public Character? Character { get; set; } = null;
|
||||
}
|
||||
}
|
||||
18
Models/Entity/PassiveItem.cs
Normal file
18
Models/Entity/PassiveItem.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class PassiveItem : Item
|
||||
{
|
||||
public PassiveSkill? Skill { get; set; } = null;
|
||||
|
||||
public PassiveItem()
|
||||
{
|
||||
Active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Models/Entity/PassiveSkill.cs
Normal file
27
Models/Entity/PassiveSkill.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class PassiveSkill : Skill
|
||||
{
|
||||
public decimal Reference1 { get; set; } = 0;
|
||||
public decimal Reference2 { get; set; } = 0;
|
||||
public decimal Reference3 { get; set; } = 0;
|
||||
public decimal Reference4 { get; set; } = 0;
|
||||
public decimal Reference5 { get; set; } = 0;
|
||||
public decimal Reference6 { get; set; } = 0;
|
||||
public decimal Reference7 { get; set; } = 0;
|
||||
public decimal Reference8 { get; set; } = 0;
|
||||
public decimal Reference9 { get; set; } = 0;
|
||||
public decimal Reference10 { get; set; } = 0;
|
||||
|
||||
public PassiveSkill()
|
||||
{
|
||||
Active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Models/Entity/Room.cs
Normal file
33
Models/Entity/Room.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class Room
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Roomid { get; set; } = "";
|
||||
public DateTime Time { get; set; } = DateTime.Now;
|
||||
public Hashtable PlayerList { get; set; } = new Hashtable();
|
||||
public User? RoomMaster { get; set; }
|
||||
public int RoomType { get; set; }
|
||||
public int RoomState { get; set; }
|
||||
public GameStatistics? Statistics { get; set; } = null;
|
||||
|
||||
public Room(User? master = null)
|
||||
{
|
||||
if (master != null) RoomMaster = master;
|
||||
}
|
||||
|
||||
public Room(string roomid, User? master = null)
|
||||
{
|
||||
Roomid = roomid;
|
||||
if (master != null) RoomMaster = master;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Models/Entity/Skill.cs
Normal file
17
Models/Entity/Skill.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public abstract class Skill
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Describe { get; set; } = "";
|
||||
public char Key { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
23
Models/Entity/Stock.cs
Normal file
23
Models/Entity/Stock.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class Stock
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public User? User { get; set; } = null;
|
||||
public Hashtable? Characters { get; set; } = new Hashtable();
|
||||
public Hashtable? Items { get; set; } = new Hashtable();
|
||||
|
||||
public Stock()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Models/Entity/User.cs
Normal file
44
Models/Entity/User.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Userame { get; set; } = "";
|
||||
public string Password { get; set; } = "";
|
||||
public DateTime RegTime { get; set; }
|
||||
public DateTime LastTime { get; set; }
|
||||
public string Email { get; set; } = "";
|
||||
public string NickName { get; set; } = "";
|
||||
public bool IsAdmin { get; set; } = false;
|
||||
public bool IsOperator { get; set; } = false;
|
||||
public bool IsEnable { get; set; } = false;
|
||||
public int OnlineState { get; set; } = 0;
|
||||
public string Roomid { get; set; } = "";
|
||||
public int Credits { get; set; } = 0;
|
||||
public int Material { get; set; } = 0;
|
||||
public UserStatistics? Statistics { get; set; } = null;
|
||||
public Stock? Stock { get; set; } = null;
|
||||
|
||||
public User()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public User(string username)
|
||||
{
|
||||
Userame = username;
|
||||
}
|
||||
|
||||
public User(string username, string password)
|
||||
{
|
||||
Userame = username;
|
||||
Password = password;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Models/Entity/UserStatistics.cs
Normal file
35
Models/Entity/UserStatistics.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunGame.Models.Entity
|
||||
{
|
||||
public class UserStatistics
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public User? User { get; set; } = null;
|
||||
public Hashtable? DamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? PhysicalDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? MagicDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RealDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AvgDamageStats { get; set; } = new Hashtable();
|
||||
public Hashtable? KillStats { get; set; } = new Hashtable();
|
||||
public Hashtable? DeathStats { get; set; } = new Hashtable();
|
||||
public Hashtable? AssistStats { get; set; } = new Hashtable();
|
||||
public Hashtable? Plays { get; set; } = new Hashtable();
|
||||
public Hashtable? Wins { get; set; } = new Hashtable();
|
||||
public Hashtable? Loses { get; set; } = new Hashtable();
|
||||
public Hashtable? Winrates { get; set; } = new Hashtable();
|
||||
public Hashtable? RatingStats { get; set; } = new Hashtable();
|
||||
public Hashtable? EloStats { get; set; } = new Hashtable();
|
||||
public Hashtable? RankStats { get; set; } = new Hashtable();
|
||||
|
||||
public UserStatistics()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlTypes;
|
||||
using FunGameServer.Utils;
|
||||
using System.Reflection.Metadata;
|
||||
using FunGame.Models.Entity;
|
||||
|
||||
namespace FunGameServer.Sockets
|
||||
{
|
||||
@ -16,6 +18,8 @@ namespace FunGameServer.Sockets
|
||||
public bool Running { get; set; } = false;
|
||||
public Socket? Socket { get; set; } = null;
|
||||
|
||||
private User? user = null;
|
||||
|
||||
public ClientSocket(Socket socket, bool running)
|
||||
{
|
||||
Socket = socket;
|
||||
@ -35,19 +39,21 @@ namespace FunGameServer.Sockets
|
||||
{
|
||||
string msg = Config.DEFAULT_ENCODING.GetString(buffer, 0, length);
|
||||
int type = SocketHelper.GetType(msg);
|
||||
string typestring = SocketHelper.GetTypeString(type);
|
||||
msg = SocketHelper.GetMessage(msg);
|
||||
Console.WriteLine("收到来自:客户端(" + type + ") -> " + msg);
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "[ 客户端(" + typestring + ")] -> " + msg);
|
||||
switch (type)
|
||||
{
|
||||
case (int)SocketEnums.ReadType.GetNotice:
|
||||
case (int)SocketEnums.Type.GetNotice:
|
||||
break;
|
||||
case (int)SocketEnums.ReadType.Login:
|
||||
case (int)SocketEnums.Type.Login:
|
||||
break;
|
||||
case (int)SocketEnums.ReadType.CheckLogin:
|
||||
case (int)SocketEnums.Type.CheckLogin:
|
||||
return true;
|
||||
case (int)SocketEnums.Type.Logout:
|
||||
break;
|
||||
case (int)SocketEnums.ReadType.Logout:
|
||||
break;
|
||||
case (int)SocketEnums.ReadType.HeartBeat:
|
||||
case (int)SocketEnums.Type.HeartBeat:
|
||||
msg = "";
|
||||
break;
|
||||
}
|
||||
return Send(socket, type, msg);
|
||||
@ -56,7 +62,7 @@ namespace FunGameServer.Sockets
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("ERROR:客户端没有回应。\n" + e.StackTrace);
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "ERROR:客户端没有回应。\n" + e.StackTrace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -68,16 +74,20 @@ namespace FunGameServer.Sockets
|
||||
{
|
||||
byte[] buffer = new byte[2048];
|
||||
buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(SocketHelper.MakeMessage(type, msg)));
|
||||
string typestring = SocketHelper.GetTypeString(type);
|
||||
if (socket.Send(buffer) > 0)
|
||||
{
|
||||
Console.WriteLine("发送给:客户端(" + type + ") <- " + msg);
|
||||
if (msg != "")
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "[ 客户端(" + typestring + ")] <- " + msg);
|
||||
else
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "-> [ 客户端(" + typestring + ")]");
|
||||
return true;
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("ERROR:客户端没有回应。" + e.StackTrace);
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "ERROR:客户端没有回应。" + e.StackTrace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -93,7 +103,7 @@ namespace FunGameServer.Sockets
|
||||
private void CreateStreamReader()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
Console.WriteLine("Creating: StreamReader...OK");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "Creating: StreamReader...OK");
|
||||
while (Running)
|
||||
{
|
||||
if (Socket != null)
|
||||
@ -103,8 +113,8 @@ namespace FunGameServer.Sockets
|
||||
FailedTimes++;
|
||||
if (FailedTimes >= Config.MAX_CONNECTFAILED)
|
||||
{
|
||||
Console.WriteLine("ERROR: Too Many Faileds.");
|
||||
Console.WriteLine("DONE: StreamReader is Closed.");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "ERROR: Too Many Faileds.");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "CLOSE: StreamReader is Closed.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -112,8 +122,8 @@ namespace FunGameServer.Sockets
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("ERROR: Socket is Closed.");
|
||||
Console.WriteLine("DONE: StringStream is Closed.");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "ERROR: Socket is Closed.");
|
||||
Console.WriteLine(SocketHelper.GetPrefix() + "CLOSE: StringStream is Closed.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using FunGameServer.Models.Config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -17,6 +18,25 @@ namespace FunGameServer.Utils
|
||||
return Convert.ToInt32(msg[..1]);
|
||||
}
|
||||
|
||||
public static string GetTypeString(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case (int)SocketEnums.Type.GetNotice:
|
||||
return SocketEnums.TYPE_GetNotice;
|
||||
case (int)SocketEnums.Type.Login:
|
||||
return SocketEnums.TYPE_Login;
|
||||
case (int)SocketEnums.Type.CheckLogin:
|
||||
return SocketEnums.TYPE_CheckLogin;
|
||||
case (int)SocketEnums.Type.Logout:
|
||||
return SocketEnums.TYPE_Logout;
|
||||
case (int)SocketEnums.Type.HeartBeat:
|
||||
return SocketEnums.TYPE_HeartBeat;
|
||||
default:
|
||||
return SocketEnums.TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetMessage(string msg)
|
||||
{
|
||||
int index = msg.IndexOf(';') + 1;
|
||||
@ -27,5 +47,11 @@ namespace FunGameServer.Utils
|
||||
{
|
||||
return type + ";" + msg;
|
||||
}
|
||||
|
||||
public static string GetPrefix()
|
||||
{
|
||||
DateTime now = System.DateTime.Now;
|
||||
return now.AddMilliseconds(-now.Millisecond).ToString() + " " + Config.SERVER_NAME + ":";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user