mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
添加RoomList
This commit is contained in:
parent
686c67dc58
commit
59d70fb3a0
@ -1,28 +1,53 @@
|
|||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Interface.Entity;
|
||||||
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Entity
|
namespace Milimoe.FunGame.Core.Entity
|
||||||
{
|
{
|
||||||
public class Room
|
public class Room : BaseEntity
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
|
||||||
public string Roomid { get; set; } = "";
|
public string Roomid { get; set; } = "";
|
||||||
public DateTime Time { get; set; } = DateTime.Now;
|
public DateTime Time { get; set; } = DateTime.Now;
|
||||||
public Hashtable PlayerList { get; set; } = new Hashtable();
|
public Hashtable PlayerList { get; set; } = new Hashtable();
|
||||||
public User? RoomMaster { get; set; }
|
public User? RoomMaster { get; set; }
|
||||||
public RoomType RoomType { get; set; }
|
public RoomType RoomType { get; set; }
|
||||||
public RoomState RoomState { get; set; }
|
public RoomState RoomState { get; set; }
|
||||||
|
public bool HasPass
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (RoomType == RoomType.MixHasPass || RoomType == RoomType.TeamHasPass)
|
||||||
|
return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string Password { get; set; } = "";
|
||||||
public GameStatistics? Statistics { get; set; } = null;
|
public GameStatistics? Statistics { get; set; } = null;
|
||||||
|
|
||||||
internal Room(User? master = null)
|
internal Room(User? master = null)
|
||||||
{
|
{
|
||||||
if (master != null) RoomMaster = master;
|
if (master != null) RoomMaster = master;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Room(string roomid, User? master = null)
|
internal Room(string roomid, User? master = null)
|
||||||
{
|
{
|
||||||
Roomid = roomid;
|
Roomid = roomid;
|
||||||
if (master != null) RoomMaster = master;
|
if (master != null) RoomMaster = master;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Equals(Room other)
|
||||||
|
{
|
||||||
|
return other.Id == Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerator<Room> GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(IBaseEntity? other)
|
||||||
|
{
|
||||||
|
return Equals(other);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,12 +23,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
private bool _Receiving;
|
private bool _Receiving;
|
||||||
private string _ClientName;
|
private string _ClientName;
|
||||||
|
|
||||||
public ClientSocket(System.Net.Sockets.Socket Instance, int ServerPort, string ClientIP, string ClientName)
|
public ClientSocket(System.Net.Sockets.Socket Instance, int ServerPort, string ClientIP, string ClientName, Guid Token)
|
||||||
{
|
{
|
||||||
this.Instance= Instance;
|
this.Instance= Instance;
|
||||||
this.ServerPort = ServerPort;
|
this.ServerPort = ServerPort;
|
||||||
this.ClientIP = ClientIP;
|
this.ClientIP = ClientIP;
|
||||||
this._ClientName = ClientName;
|
this._ClientName = ClientName;
|
||||||
|
this.Token = Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
|||||||
@ -38,14 +38,14 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
else throw new SocketCreateListenException();
|
else throw new SocketCreateListenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSocket Accept()
|
public ClientSocket Accept(Guid Token)
|
||||||
{
|
{
|
||||||
object[] result = SocketManager.Accept();
|
object[] result = SocketManager.Accept();
|
||||||
if (result != null && result.Length == 2)
|
if (result != null && result.Length == 2)
|
||||||
{
|
{
|
||||||
string ClientIP = (string)result[0];
|
string ClientIP = (string)result[0];
|
||||||
System.Net.Sockets.Socket Client = (System.Net.Sockets.Socket)result[1];
|
System.Net.Sockets.Socket Client = (System.Net.Sockets.Socket)result[1];
|
||||||
return new ClientSocket(Client, ServerPort, ClientIP, ClientIP);
|
return new ClientSocket(Client, ServerPort, ClientIP, ClientIP, Token);
|
||||||
}
|
}
|
||||||
throw new SocketGetClientException();
|
throw new SocketGetClientException();
|
||||||
}
|
}
|
||||||
|
|||||||
45
FunGame.Core/Library/Server/RoomList.cs
Normal file
45
FunGame.Core/Library/Server/RoomList.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using Milimoe.FunGame.Core.Entity;
|
||||||
|
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||||
|
|
||||||
|
namespace Milimoe.FunGame.Core.Library.Server
|
||||||
|
{
|
||||||
|
public class RoomList
|
||||||
|
{
|
||||||
|
public ServerSocket Server => _Server;
|
||||||
|
public int Count => _List.Count;
|
||||||
|
|
||||||
|
private readonly ServerSocket _Server;
|
||||||
|
private readonly Hashtable _List = new();
|
||||||
|
|
||||||
|
public RoomList(ServerSocket Server)
|
||||||
|
{
|
||||||
|
_Server = Server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Room> GetList()
|
||||||
|
{
|
||||||
|
return _List.Values.Cast<Room>().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRoom(Room Room)
|
||||||
|
{
|
||||||
|
_List.Add(Room.Name, Room);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRoom(Room Room)
|
||||||
|
{
|
||||||
|
_List.Remove(Room.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Room? GetRoom(string RoomID)
|
||||||
|
{
|
||||||
|
Room? room = null;
|
||||||
|
if (_List.ContainsKey(RoomID))
|
||||||
|
{
|
||||||
|
room = (Room?)_List[RoomID];
|
||||||
|
}
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -155,7 +155,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用于客户端接收服务器信息
|
/// 用于客户端接收服务器信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>通信类型[0]和参数[1]</returns>
|
/// <returns>SocketObject</returns>
|
||||||
internal static Library.Common.Network.SocketObject Receive()
|
internal static Library.Common.Network.SocketObject Receive()
|
||||||
{
|
{
|
||||||
Library.Common.Network.SocketObject result = default;
|
Library.Common.Network.SocketObject result = default;
|
||||||
@ -184,7 +184,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
/// 用于服务器接收客户端信息
|
/// 用于服务器接收客户端信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ClientSocket">客户端Socket</param>
|
/// <param name="ClientSocket">客户端Socket</param>
|
||||||
/// <returns>通信类型[0]、Token[1]和参数[2]</returns>
|
/// <returns>SocketObject</returns>
|
||||||
internal static Library.Common.Network.SocketObject Receive(Socket ClientSocket)
|
internal static Library.Common.Network.SocketObject Receive(Socket ClientSocket)
|
||||||
{
|
{
|
||||||
Library.Common.Network.SocketObject result = default;
|
Library.Common.Network.SocketObject result = default;
|
||||||
|
|||||||
@ -137,6 +137,11 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Config.FunGame_isRetrying = false;
|
||||||
|
Socket.Close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return ConnectResult.Success;
|
return ConnectResult.Success;
|
||||||
}
|
}
|
||||||
@ -238,7 +243,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case SocketMessageType.Connect:
|
case SocketMessageType.Connect:
|
||||||
SocketHandler_Connect(ServerMessage);
|
if (!SocketHandler_Connect(ServerMessage)) return SocketMessageType.Unknown;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SocketMessageType.Disconnect:
|
case SocketMessageType.Disconnect:
|
||||||
@ -267,12 +272,20 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
|
|
||||||
#region SocketHandler
|
#region SocketHandler
|
||||||
|
|
||||||
private void SocketHandler_Connect(SocketObject ServerMessage)
|
private bool SocketHandler_Connect(SocketObject ServerMessage)
|
||||||
{
|
{
|
||||||
string msg = "";
|
string msg = "";
|
||||||
Guid token = Guid.Empty;
|
Guid token = Guid.Empty;
|
||||||
if (ServerMessage.Parameters.Length > 0) msg = ServerMessage.GetParam<string>(0)!;
|
if (ServerMessage.Parameters.Length > 0) msg = ServerMessage.GetParam<string>(0)!;
|
||||||
string[] strings = msg.Split(';');
|
string[] strings = msg.Split(';');
|
||||||
|
if (strings.Length != 2)
|
||||||
|
{
|
||||||
|
// 服务器拒绝连接
|
||||||
|
msg = strings[0];
|
||||||
|
Main.GetMessage(msg);
|
||||||
|
ShowMessage.ErrorMessage(msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
string ServerName = strings[0];
|
string ServerName = strings[0];
|
||||||
string ServerNotice = strings[1];
|
string ServerNotice = strings[1];
|
||||||
Config.FunGame_ServerName = ServerName;
|
Config.FunGame_ServerName = ServerName;
|
||||||
@ -283,6 +296,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
|
Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
|
||||||
// 设置等待登录的黄灯
|
// 设置等待登录的黄灯
|
||||||
Main.UpdateUI(MainInvokeType.WaitLoginAndSetYellow);
|
Main.UpdateUI(MainInvokeType.WaitLoginAndSetYellow);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SocketHandler_Disconnect(SocketObject ServerMessage)
|
private void SocketHandler_Disconnect(SocketObject ServerMessage)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user