Ejemplo n.º 1
0
        public HeadServer()
        {
            var name = "Head1";
            Logger.Start(name);

            qManager = new QueueManager(name,
                                        new QueueManagerOptions(new[] {
                                                                              new QueueWatcher("HeadServer", null),
                                                                              new QueueWatcher(name, null),
                                                                      },
                                                                new[] {
                                                                              "GatewayServer"
                                                                      }));

            fs.ReadFile(__dirname + "/index.html", "ascii", ready);

            pubsub = new PubSub(() => pubsub.Subscribe<string>("PUBSUB.GatewayServers",
                                                               message => {
                                                                   indexForSites.Add(indexPageData.Replace("{{gateway}}", message));
                                                                   gateways.Add(message);
                                                               }));

            Global.Require<Http>("http").CreateServer(handlerWS).Listen(8844);

            Global.SetInterval(pollGateways, 5000);
            pollGateways();
        }
Ejemplo n.º 2
0
        public ServerLogListener(string serverType, Action<ServerLogMessage> callback)
        {

            ServerType = serverType;
            pubsub =
                new PubSub(
                    (ps) =>
                        ps.Subscribe(string.Format("PUBSUB.ServerLogger.{0}", ServerType),
                            (content) => callback(Json.Parse<ServerLogMessage>(content))));
        }
Ejemplo n.º 3
0
        public static void InitLogger(string serverType, string serverName)
        {

            ServerName = serverName;
            ServerType = serverType;
            pubsub = new PubSub((ps) =>
                                {
                                    Global.SetInterval(() => LogKeepAlive(), 500);
                                });
        }
Ejemplo n.º 4
0
        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++;1
                               },200);*/

            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("GatewayServer", messageReceived),
                                                                                  new QueueWatcher(myGatewayName, messageReceived)
                                                                          },
                                                                    new[] {
                                                                                  "SiteServer",
                                                                                  "GameServer*",
                                                                                  "GameServer",
                                                                                  "DebugServer",
                                                                                  "ChatServer",
                                                                                  "ChatServer*",
                                                                                  "HeadServer"
                                                                          }));
            io.Sockets.On("connection",
                          (SocketIOConnection socket) => {
                              var j = ++curc;
                              Console.Log("Socket Connected "+j);
                              UserSocketModel user = null;
                              socket.On("Gateway.Message",
                                        (GatewayMessageModel data) => {
                                            if (user == null)
                                                return;
                                            Console.Log("Socket message " + j + "  " + user.UserName);

                                            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) => {
                                            ExtensionMethods.debugger();
                                            user = new UserSocketModel();
                                            user.Password = data.Password;
                                            user.Socket = socket;
                                            user.UserName = data.UserName;
                                            user.Hash = data.UserName;
                                            user.Gateway = myGatewayName;

                                            Console.Log("Socket login " + j + "  " + data.UserName);

                                            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;
                                            Console.Log("Socket left " + j + "  " + user.UserName);

                                            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);
                                            socket.RemoveAllListeners();
                                            //socket.Delete();
                                            io.Sockets.Sockets.Remove(socket.ID);
                                            curc--;
                                        });
                          });
        }