mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-04-22 03:59:36 +08:00
重新封装SocketManager
This commit is contained in:
parent
d582dd753f
commit
ec596e964e
@ -8,7 +8,7 @@ using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Utility;
|
||||
|
||||
Console.Title = Config.ServerName;
|
||||
Console.WriteLine(FunGameInfo.GetInfo((FunGameInfo.FunGame)Config.FunGameType));
|
||||
Console.WriteLine(FunGameInfo.GetInfo(Config.FunGameType));
|
||||
|
||||
bool Running = true;
|
||||
ServerSocket? ListeningSocket = null;
|
||||
@ -148,10 +148,10 @@ void StartServer()
|
||||
bool Read(ClientSocket socket)
|
||||
{
|
||||
// 接收客户端消息
|
||||
byte[] buffer = new byte[2048];
|
||||
object[] read = socket.Receive();
|
||||
SocketMessageType type = (SocketMessageType)read[0];
|
||||
object[] objs = (object[])read[2];
|
||||
byte[] buffer = new byte[General.SocketByteSize];
|
||||
SocketObject read = socket.Receive();
|
||||
SocketMessageType type = read.SocketType;
|
||||
object[] objs = read.Parameters;
|
||||
if (type != SocketMessageType.Unknown)
|
||||
{
|
||||
if (objs[0] != null && objs[0].GetType() == typeof(string) && objs[0].ToString()!.Trim() != "")
|
||||
|
@ -56,10 +56,10 @@ namespace Milimoe.FunGame.Server.Model
|
||||
// 接收客户端消息
|
||||
try
|
||||
{
|
||||
object[] objs = socket.Receive();
|
||||
SocketMessageType type = (SocketMessageType)objs[0];
|
||||
Guid token = (Guid)objs[1];
|
||||
object[] args = (object[])objs[2];
|
||||
SocketObject SocketObject = socket.Receive();
|
||||
SocketMessageType type = SocketObject.SocketType;
|
||||
Guid token = SocketObject.Token;
|
||||
object[] args = SocketObject.Parameters;
|
||||
string msg = "";
|
||||
|
||||
// 如果不等于这些Type,就不会输出一行记录。这些Type有特定的输出。
|
||||
@ -84,9 +84,9 @@ namespace Milimoe.FunGame.Server.Model
|
||||
if (args != null)
|
||||
{
|
||||
string? username = "", password = "", autokey = "";
|
||||
if (args.Length > 0) username = NetworkUtility.ConvertJsonObject<string>(args[0]);
|
||||
if (args.Length > 1) password = NetworkUtility.ConvertJsonObject<string>(args[1]);
|
||||
if (args.Length > 2) autokey = NetworkUtility.ConvertJsonObject<string>(args[2]);
|
||||
if (args.Length > 0) username = SocketObject.GetParam<string>(0);
|
||||
if (args.Length > 1) password = SocketObject.GetParam<string>(1);
|
||||
if (args.Length > 2) autokey = SocketObject.GetParam<string>(2);
|
||||
if (username != null && password != null)
|
||||
{
|
||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] UserName: " + username);
|
||||
@ -111,7 +111,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
case SocketMessageType.CheckLogin:
|
||||
if (args != null && args.Length > 0)
|
||||
{
|
||||
Guid checkloginkey = NetworkUtility.ConvertJsonObject<Guid>(args[0]);
|
||||
Guid checkloginkey = SocketObject.GetParam<Guid>(0);
|
||||
if (CheckLoginKey.Equals(checkloginkey))
|
||||
{
|
||||
// 创建User对象
|
||||
@ -134,7 +134,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
Guid checklogoutkey = Guid.Empty;
|
||||
if (args != null && args.Length > 0)
|
||||
{
|
||||
checklogoutkey = NetworkUtility.ConvertJsonObject<Guid>(args[0]);
|
||||
checklogoutkey = SocketObject.GetParam<Guid>(0);
|
||||
if (CheckLoginKey.Equals(checklogoutkey))
|
||||
{
|
||||
// 从玩家列表移除
|
||||
@ -159,12 +159,12 @@ namespace Milimoe.FunGame.Server.Model
|
||||
|
||||
case SocketMessageType.IntoRoom:
|
||||
msg = "-1";
|
||||
if (args != null && args.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(args[0])!;
|
||||
if (args != null && args.Length > 0) msg = SocketObject.GetParam<string>(0)!;
|
||||
RoomID = msg;
|
||||
break;
|
||||
|
||||
case SocketMessageType.Chat:
|
||||
if (args != null && args.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(args[0])!;
|
||||
if (args != null && args.Length > 0) msg = SocketObject.GetParam<string>(0)!;
|
||||
ServerHelper.WriteLine(msg);
|
||||
foreach (ServerModel Client in Server.GetUsersList.Cast<ServerModel>())
|
||||
{
|
||||
@ -182,8 +182,8 @@ namespace Milimoe.FunGame.Server.Model
|
||||
if (args != null)
|
||||
{
|
||||
string? username = "", email = "";
|
||||
if (args.Length > 0) username = NetworkUtility.ConvertJsonObject<string>(args[0]);
|
||||
if (args.Length > 1) email = NetworkUtility.ConvertJsonObject<string>(args[1]);
|
||||
if (args.Length > 0) username = SocketObject.GetParam<string>(0);
|
||||
if (args.Length > 1) email = SocketObject.GetParam<string>(1);
|
||||
if (username != null && email != null)
|
||||
{
|
||||
// 先检查账号是否重复
|
||||
@ -254,10 +254,10 @@ namespace Milimoe.FunGame.Server.Model
|
||||
if (args != null)
|
||||
{
|
||||
string? username = "", password = "", email = "", verifycode = "";
|
||||
if (args.Length > 0) username = NetworkUtility.ConvertJsonObject<string>(args[0]);
|
||||
if (args.Length > 1) password = NetworkUtility.ConvertJsonObject<string>(args[1]);
|
||||
if (args.Length > 2) email = NetworkUtility.ConvertJsonObject<string>(args[2]);
|
||||
if (args.Length > 3) verifycode = NetworkUtility.ConvertJsonObject<string>(args[3]);
|
||||
if (args.Length > 0) username = SocketObject.GetParam<string>(0);
|
||||
if (args.Length > 1) password = SocketObject.GetParam<string>(1);
|
||||
if (args.Length > 2) email = SocketObject.GetParam<string>(2);
|
||||
if (args.Length > 3) verifycode = SocketObject.GetParam<string>(3);
|
||||
if (username != null && password != null && email != null && verifycode != null)
|
||||
{
|
||||
// 先检查验证码
|
||||
|
Loading…
x
Reference in New Issue
Block a user