Пример #1
0
        public static ServerStatusFlipbookIcon GetCurrentServerLoadIcon(GameServerInformation serverInformation)
        {
            if (!serverInformation.IsOnline)
            {
                return(ServerStatusFlipbookIconPresets[ServerStatus.Offline]);
            }

            float serverLoad = serverInformation.ConnectedClients / (float)serverInformation.ConnectedClientCapacity;

            if (serverLoad < 0.2f)
            {
                return(ServerStatusFlipbookIconPresets[ServerStatus.LowPopulation]);
            }
            else if (serverLoad < 0.5f)
            {
                return(ServerStatusFlipbookIconPresets[ServerStatus.MediumPopulation]);
            }
            else if (serverLoad < 0.7f)
            {
                return(ServerStatusFlipbookIconPresets[ServerStatus.HighPopulation]);
            }
            else
            {
                return(ServerStatusFlipbookIconPresets[ServerStatus.Full]);
            }
        }
Пример #2
0
        //Game Server Handlers
        #region Connection
        public static void ConnectToGameServer(GameServerInformation serverInformation)
        {
            ServerInformationBroker.Instance.ConnectToGameServer(serverInformation);

            ServerInformationBroker.Instance.GameServerServiceProvider.RequestQueue.Enqueue(
                NetworkObjectParameters.GameServerPlayerAccessRequest,
                GameInformation.Instance.PlayerInformation);
        }
Пример #3
0
        public void ConnectToGameServer(GameServerInformation serverInformation)
        {
            GameServerServiceProvider = new ClientServiceProvider(
                serverInformation.ServerPublicAddress, serverInformation.ServerPort,
                NetworkObjectParameters.LobbyServerBufferSize,
                GameServerConsumerAction);

            GameServerServiceProvider.StartOperation();
        }
Пример #4
0
        public void ConnectToGameServer(GameServerInformation serverInformation)
        {
            GameServerServiceProvider = new ClientServiceProvider(
                serverInformation.ServerPublicAddress, serverInformation.ServerPort,
                NetworkObjectParameters.LobbyServerBufferSize,
                GameServerConsumerAction);

            GameServerServiceProvider.StartOperation();

            GameServerServiceProvider.OnDisconnect += OnDisconnect;

            //If the application fails to send or to receive, force the disconnection
            GameServerServiceProvider.OnFailToSendMessage        =
                GameServerServiceProvider.OnFailToReceiveMessage = (ex) => { return(true); };
        }
Пример #5
0
        public static void ServerListHandle(string request)
        {
            try
            {
                GameServerInformation si = ObjectWrapper.DeserializeRequest <GameServerInformation>(request);

                lock (GameInformation.Instance.ServerList)
                {
                    if (GameInformation.Instance.ServerList == null)
                    {
                        GameInformation.Instance.ServerList = new List <GameServerInformation>();
                    }
                    GameInformation.Instance.ServerList.Add(si);
                }
            }
            catch (Exception) { }
        }
Пример #6
0
        public static bool RefreshGameServerStatusRequest(string param, Dictionary <int, object> paramDictionary)
        {
            try
            {
                GameServerInformation information = ObjectWrapper.DeserializeRequest <GameServerInformation>(param);

                if (!NetworkObjectParameters.GameServerRequestIPWhitelist.Contains(information.ServerPublicAddress))
                {
                    Console.WriteLine(
                        $"- {information.ServerConsoleName} is attempting to register but it is not on the whitelist.\n" +
                        $"Whitelisted servers: {string.Join(", ", NetworkObjectParameters.GameServerRequestIPWhitelist)}");

                    return(false);
                }

                lock (LobbyServerObjects.ServerInformationList)
                {
                    GameServerInformation si = LobbyServerObjects.ServerInformationList.Find((x) => x.ServerID == information.ServerID);

                    if (si == null)
                    {
                        LobbyServerObjects.ServerInformationList.Add(information);
                    }
                    else
                    {
                        LobbyServerObjects.ServerInformationList.Remove(si);
                        LobbyServerObjects.ServerInformationList.Add(information);
                    }

                    information.IsOnline = true;

                    LobbyServerObjects.ServerInformationList = LobbyServerObjects.ServerInformationList.OrderBy((x) => x.ServerID).ToList();

                    paramDictionary.Add(NetworkObjectParameters.GameServerRegisterRequest, information);
                }

                Console.WriteLine($"- {information.ServerName}:{information.ServerPublicAddress}:{information.ServerPort} refreshed its status. ");

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        public ServerButton(GameServerInformation serverInformation, Vector2 buttonPosition, Action <object> action)
            : base(ButtonType.ServerListButton, DepthParameter.InterfaceButton, action, buttonPosition, default)
        {
            //Since the button elements dont update, the screencenter
            //must be added in order to create the right position
            //on the elements
            buttonPosition += Parameter.ScreenCenter;

            //Initializing Variables
            compositeSpriteTextList = new List <CompositeSpriteText>();
            spriteList        = new List <Sprite>();
            flipbookList      = new List <Flipbook>();
            spriteTextList    = new List <SpriteText>();
            ServerInformation = serverInformation;

            //Server Background
            if (!serverInformation.IsOnline)
            {
                ChangeButtonState(ButtonAnimationState.Disabled);
            }

            //Server Level Indication Icons
            int lowerLevel  = (int)serverInformation.LowerLevel;
            int higherLevel = (int)serverInformation.HigherLevel;

            Sprite lowerLevelIcon  = IconBuilder.Instance.BuildServerIcon((ServerRankLimitationIcon)(lowerLevel * 2), DepthParameter.InterfaceButtonText);
            Sprite higherLevelIcon = IconBuilder.Instance.BuildServerIcon((ServerRankLimitationIcon)(higherLevel * 2 + 1), DepthParameter.InterfaceButtonText);
            Sprite avatarIcon      = IconBuilder.Instance.BuildServerIcon((serverInformation.IsAvatarOn ? ServerRankLimitationIcon.AvatarOn : ServerRankLimitationIcon.AvatarOff), DepthParameter.InterfaceButtonText);

            lowerLevelIcon.Position  = buttonPosition + new Vector2(40, -24);
            higherLevelIcon.Position = buttonPosition + new Vector2(68, -24);
            avatarIcon.Position      = buttonPosition + new Vector2(96, -24);

            spriteList.Add(lowerLevelIcon);
            spriteList.Add(higherLevelIcon);
            spriteList.Add(avatarIcon);

            //Server Load Icon
            ServerStatusFlipbookIcon serverLoad = GetCurrentServerLoadIcon(serverInformation);
            Flipbook icon = new Flipbook(
                buttonPosition + new Vector2(130, 12), new Vector2(31, 37), 62, 58,
                "Interface/InGame/Scene/ServerList/ServerStatusAnimatedIcon", serverLoad.FlipbookInstance, DepthParameter.InterfaceButtonAnimatedIcon);

            flipbookList.Add(icon);

            //Server Button Texts
            SpriteText[] sprT = new SpriteText[2];
            sprT[0] = new SpriteText(Parameter.ServerButtonFont, $"{serverInformation.ServerID}. ", Color.DarkOrange,
                                     Alignment.Left, DepthParameter.InterfaceButtonText, outlineColor: Color.Black);

            sprT[1] = new SpriteText(Parameter.ServerButtonFont, serverInformation.ServerName, Color.White,
                                     Alignment.Left, DepthParameter.InterfaceButtonText, outlineColor: Color.Black);

            compositeSpriteTextList.Add(
                CompositeSpriteText.CreateCompositeSpriteText(sprT.ToList(), Orientation.Horizontal, Alignment.Left, buttonPosition + new Vector2(-155, -32), 0));

            sprT = new SpriteText[serverInformation.ServerDescription.Count()];
            for (int i = 0; i < serverInformation.ServerDescription.Count(); i++)
            {
                sprT[i] = new SpriteText(Parameter.ServerButtonFont, serverInformation.ServerDescription[i], Color.White,
                                         Alignment.Left, DepthParameter.InterfaceButtonText, outlineColor: Color.Black);
            }

            compositeSpriteTextList.Add(CompositeSpriteText.CreateCompositeSpriteText(sprT.ToList(), Orientation.Vertical, Alignment.Left, buttonPosition + new Vector2(-155, -10), -1));

            if (serverInformation.IsOnline)
            {
                spriteTextList.Add(new SpriteText(Parameter.ServerButtonFont, $"[{serverInformation.ConnectedClients}/{serverInformation.ConnectedClientCapacity}]", Color.White,
                                                  Alignment.Center, DepthParameter.InterfaceButtonText, buttonPosition + new Vector2(68, -10), Color.Black));
            }

            //Server Icon Text
            spriteTextList.Add(new SpriteText(Parameter.ServerButtonFont,
                                              serverLoad.IconSubtitle, Color.White, Alignment.Center,
                                              DepthParameter.InterfaceButtonText, icon.Position + new Vector2(0, 10), Color.Black));

            OnBeingPressed = (sender) =>
            {
                spriteTextList.ForEach((x) => x.Position += new Vector2(1, 1));
                spriteList.ForEach((x) => x.Position     += new Vector2(1, 1));
                flipbookList.ForEach((x) => x.Position   += new Vector2(1, 1));
            };

            OnBeingReleased = (sender) =>
            {
                spriteTextList.ForEach((x) => x.Position -= new Vector2(1, 1));
                spriteList.ForEach((x) => x.Position     -= new Vector2(1, 1));
                flipbookList.ForEach((x) => x.Position   -= new Vector2(1, 1));
            };
        }