上传战斗优化

This commit is contained in:
liwei1dao 2022-12-12 17:43:40 +08:00
parent 0648f41645
commit 00ee9c35ab
2 changed files with 12 additions and 0 deletions

View File

@ -13,6 +13,11 @@ namespace BattleServer
{ {
socket = _socket; socket = _socket;
socket.OnBinary = doBinary; socket.OnBinary = doBinary;
socket.OnClose = close;
}
private void close (){
Service.Instance.Shutdown(this);
} }
/// <summary> /// <summary>

View File

@ -10,6 +10,7 @@ namespace BattleServer
/// </summary> /// </summary>
class Service class Service
{ {
public static Service Instance;
private WebSocketServer server; private WebSocketServer server;
private List<Client> clients; private List<Client> clients;
@ -18,6 +19,7 @@ namespace BattleServer
var server = new WebSocketServer("ws://127.0.0.1:9897"); //创建webscoket服务端实例 var server = new WebSocketServer("ws://127.0.0.1:9897"); //创建webscoket服务端实例
server.Start(onAccept); server.Start(onAccept);
clients = new List<Client>(); clients = new List<Client>();
Instance = this;
} }
private void onAccept(IWebSocketConnection webSocket) private void onAccept(IWebSocketConnection webSocket)
@ -26,5 +28,10 @@ namespace BattleServer
Console.WriteLine("新的连接对象进入{0}", client.ToString()); Console.WriteLine("新的连接对象进入{0}", client.ToString());
clients.Add(client); clients.Add(client);
} }
public void Shutdown(Client client){
Console.WriteLine("连接对象断开{0}", client.ToString());
this.clients.Remove(client);
}
} }
} }