This commit is contained in:
陈向学 2024-03-01 10:19:58 +08:00
parent 133e6f6534
commit e1bde99244
1 changed files with 0 additions and 6 deletions

View File

@ -12,14 +12,10 @@ namespace GameServer
internal class Program internal class Program
{ {
private static ConcurrentDictionary<string, TcpClient> clients = new ConcurrentDictionary<string, TcpClient>(); private static ConcurrentDictionary<string, TcpClient> clients = new ConcurrentDictionary<string, TcpClient>();
public static SubscriberSocket ToClientSubscriber;
public static PublisherSocket ToClientPublisher;
static void Main(string[] args) static void Main(string[] args)
{ {
Task.Run(RunServer); Task.Run(RunServer);
ToClientPublisher = new PublisherSocket();
ToClientPublisher.Bind("tcp://*:8888");
} }
static async Task RunServer() static async Task RunServer()
@ -75,7 +71,6 @@ namespace GameServer
Console.WriteLine($"创建房间 {commands[1]}"); Console.WriteLine($"创建房间 {commands[1]}");
var room = Room.Create(commands[1], user.userId); var room = Room.Create(commands[1], user.userId);
response = Encoding.UTF8.GetBytes(string.Format("createroom {0},{1},{2}", room.roomId, room.roomname, room.creater)); response = Encoding.UTF8.GetBytes(string.Format("createroom {0},{1},{2}", room.roomId, room.roomname, room.creater));
ToClientSubscriber.Subscribe(room.roomId.ToString());
Console.WriteLine("订阅:" + room.roomId.ToString()); Console.WriteLine("订阅:" + room.roomId.ToString());
await stream.WriteAsync(response, 0, response.Length); await stream.WriteAsync(response, 0, response.Length);
break; break;
@ -122,7 +117,6 @@ namespace GameServer
if (!string.IsNullOrWhiteSpace(close)) if (!string.IsNullOrWhiteSpace(close))
{ {
response = Encoding.UTF8.GetBytes(string.Format("closeroom {0}", close)); response = Encoding.UTF8.GetBytes(string.Format("closeroom {0}", close));
ToClientSubscriber.Unsubscribe(close);
Console.WriteLine("退订:" + close); Console.WriteLine("退订:" + close);
await stream.WriteAsync(response, 0, response.Length); await stream.WriteAsync(response, 0, response.Length);
} }