public GameServer() { fs = Global.Require<FS>("fs"); childProcess = Global.Require<ChildProcess>("child_process"); dataManager = new DataManager(); gameServerIndex = "GameServer" + Guid.NewGuid(); cachedGames = new JsDictionary<string, GameObject>(); Global.Require<NodeModule>("fibers"); rooms = new List<GameRoom>(); gameData = new GameData(); Global.Process.On("exit", () => Console.Log("exi")); /*qManager.AddChannel("Area.Game.Create", (arg1, arg2) => { GameRoom room; rooms.Add(room = new GameRoom()); });*/ qManager = new QueueManager(gameServerIndex, new QueueManagerOptions(new[] { new QueueWatcher("GameServer", null), new QueueWatcher(gameServerIndex, null), }, new[] { "GameServer", "GatewayServer", "Gateway*" })); qManager.AddChannel<SomeModel>("SomeNamespaceOrEnum??", (user, data) => { EmitAll(room, "Area.Game.UpdateState", new Compressor().CompressText(Json.Stringify(room.Game.CardGame.CleanUp()))); var user = getPlayerByUsername(room, answ.User.UserName); qManager.SendMessage(user, user.Gateway, "Area.Game.AskQuestion", gameAnswer.CleanUp()); }); }
public GatewayServer() { myGatewayName = "Gateway " + Guid.NewGuid(); /* var charm = Charmer.Setup(); var prog = new ProgressBar(charm, 0, 100) {X = 5, Y = 5, Width = 10, CurValue = 12}; Global.SetInterval(() => { prog.CurValue++; },200); */ ServerLogger.InitLogger("GatewayServer",myGatewayName); Logger.Start(myGatewayName); //ExtensionMethods.debugger(""); var http = Global.Require<Http>("http"); var app = http.CreateServer((req, res) => res.End()); var io = Global.Require<SocketIO>("socket.io").Listen(app); var fs = Global.Require<FS>("fs"); QueueManager queueManager; var port = 1800 + Math.Truncate((Math.Random() * 4000d)); port = 1800; string currentSubdomain = "gateway1"; string currentIP = ServerHelper.GetNetworkIPs()[0] + ":" + port; string content; if (Constants.Local) content = string.Format("http://{0}", currentIP); else content = string.Format("http://{0}.{1}", currentSubdomain, "anycardgame.com"); ServerLogger.LogInformation("Server URL", content); app.Listen(port); io.Set("log level", 0); new PubSub((ps) => { ps.Subscribe ("PUBSUB.GatewayServers.Ping", message => { ps.Publish("PUBSUB.GatewayServers", content); // ps.Publish("PUBSUB.GatewayServers", string.Format("http://{0}:{1}", currentIP, port)); }); // ps.Publish("PUBSUB.GatewayServers", string.Format("http://{0}:{1}", currentIP, port)); ps.Publish("PUBSUB.GatewayServers", content); }); queueManager = new QueueManager(myGatewayName, new QueueManagerOptions(new[] { new QueueWatcher("GatewayServer", messageReceived), new QueueWatcher(myGatewayName, messageReceived) }, new[] { "SiteServer", "GameServer*", "GameServer", "DebugServer", "ChatServer", "ChatServer*", "HeadServer" })); io.Sockets.On("connection", (SocketIOConnection socket) => { var j = ++curc; ServerLogger.LogDebug("Socket Connected " + j,null); UserSocketModel user = null; socket.On("Gateway.Message", (GatewayMessageModel data) => { if (user == null) return; ServerLogger.LogDebug("Socket message " + j + " ", new {data, user}); var channel = "Bad"; switch (data.Channel.Split('.')[1]) { case "Game": channel = user.CurrentGameServer ?? "GameServer"; break; case "Site": channel = "SiteServer"; break; case "Debug": channel = user.CurrentDebugServer ?? "DebugServer"; break; case "Chat": channel = user.CurrentChatServer ?? "ChatServer"; break; } queueManager.SendMessage(channel, data.Channel, user.ToLogicModel(), data.Content); }); socket.On("Gateway.Login", (GatewayLoginMessageModel data) => { //ExtensionMethods.debugger(); user = new UserSocketModel(); user.Password = data.Password; user.Socket = socket; user.UserName = data.UserName; user.Hash = data.UserName; user.Gateway = myGatewayName; ServerLogger.LogDebug("Socket login " + j, new { data, user }); users[data.UserName] = user; queueManager.SendMessage("SiteServer", "Area.Site.Login", user.ToLogicModel(), new SiteLoginRequest(user.Hash)); }); socket.On("disconnect", (string data) => { if (user == null) return; ServerLogger.LogDebug("Socket Left " + j, new { data, user }); queueManager.SendMessage("SiteServer", "Area.Site.UserDisconnect", user.ToLogicModel(), new UserDisconnectModel(user.ToLogicModel())); //disconnecting from the room in site server disconencts from chat.. // if (user.CurrentChatServer != null) // queueManager.SendMessage(user.ToLogicModel(), user.CurrentChatServer, "Area.Chat.UserDisconnect", new UserDisconnectModel(user.ToLogicModel())); if (user.CurrentGameServer != null) queueManager.SendMessage(user.CurrentGameServer, "Area.Game.UserDisconnect", user.ToLogicModel(), new UserDisconnectModel(user.ToLogicModel())); if (user.CurrentDebugServer != null) queueManager.SendMessage(user.CurrentDebugServer, "Area.Debug.UserDisconnect", user.ToLogicModel(), new UserDisconnectModel(user.ToLogicModel())); users.Remove(user.UserName); socket.RemoveAllListeners(); //socket.Delete(); io.Sockets.Sockets.Remove(socket.ID); curc--; }); }); }
public MonitorServer() { myGatewayName = "Gateway " + Guid.NewGuid(); Logger.Start(myGatewayName); //ExtensionMethods.debugger(""); var http = Global.Require<Http>("http"); var app = http.CreateServer((req, res) => res.End()); var io = Global.Require<SocketIO>("socket.io").Listen(app); var fs = Global.Require<FS>("fs"); QueueManager queueManager; var port = 1800 + Math.Truncate((int)(Math.Random() * 4000)); string currentIP = ServerHelper.GetNetworkIPs()[0]; Console.Log(currentIP); app.Listen(port); io.Set("log level", 0); ps = new PubSub(() => { ps.Subscribe<string>("PUBSUB.GatewayServers.Ping", message => { ps.Publish("PUBSUB.GatewayServers", string.Format("http://{0}:{1}", currentIP, port)); }); ps.Publish("PUBSUB.GatewayServers", string.Format("http://{0}:{1}", currentIP, port)); }); queueManager = new QueueManager(myGatewayName, new QueueManagerOptions(new[] { new QueueWatcher("MonitorServer", messageReceived), new QueueWatcher(myGatewayName, messageReceived) }, new[] { "SiteServer", "GameServer*", "GameServer", "DebugServer", "ChatServer", "ChatServer*", "HeadServer" })); io.Sockets.On("connection", (SocketIOConnection socket) => { UserSocketModel user = null; socket.On("Gateway.Message", (GatewayMessageModel data) => { if (user == null) return; var channel = "Bad"; switch (data.Channel.Split('.')[1]) { case "Game": channel = user.CurrentGameServer ?? "GameServer"; break; case "Site": channel = "SiteServer"; break; case "Debug": channel = user.CurrentGameServer ?? "GameServer"; break; case "Debug2": channel = "DebugServer"; break; case "Chat": channel = user.CurrentChatServer ?? "ChatServer"; break; } queueManager.SendMessage(channel, data.Channel, user.ToLogicModel(), data.Content); }); socket.On("Gateway.Login", (GatewayLoginMessageModel data) => { user = new UserSocketModel(); user.Password = data.Password; user.Socket = socket; user.UserName = data.UserName; user.Hash = data.UserName; user.Gateway = myGatewayName; users[data.UserName] = user; queueManager.SendMessage("SiteServer", "Area.Site.Login", user.ToLogicModel(), new SiteLoginRequest(user.Hash)); }); socket.On("disconnect", (string data) => { if (user == null) return; queueManager.SendMessage("SiteServer", "Area.Site.UserDisconnect", user.ToLogicModel(), new UserDisconnectModel(user.ToLogicModel())); //disconnecting from the room in site server disconencts from chat.. // if (user.CurrentChatServer != null) // queueManager.SendMessage(user.ToLogicModel(), user.CurrentChatServer, "Area.Chat.UserDisconnect", new UserDisconnectModel(user.ToLogicModel())); if (user.CurrentGameServer != null) queueManager.SendMessage(user.CurrentGameServer, "Area.Game.UserDisconnect", user.ToLogicModel(), new UserDisconnectModel(user.ToLogicModel())); users.Remove(user.UserName); }); }); }