Ejemplo n.º 1
0
        public static void LobbyServiceHUB(ExtendedConcurrentQueue <byte[]> provider, string[] request, Dictionary <int, object> paramDictionary)
        {
            int    service = int.Parse(request[0]);
            object answer  = null;

            switch (service)
            {
            case NetworkObjectParameters.LobbyServerPlayerUIDRequest:
                answer = PlayerHandler.GenerateUIDForPlayerLogin(request[1]);
                break;

            case NetworkObjectParameters.LobbyServerLoginRequest:
                answer = PlayerHandler.LobbyLoginRequest(request[1]);
                break;

            case NetworkObjectParameters.GameServerRegisterRequest:
                answer = ServerInformationHandler.RefreshGameServerStatusRequest(request[1], paramDictionary);
                break;

            case NetworkObjectParameters.LobbyServerServerListRequest:
                ServerInformationHandler.GameServerListRequest(provider);
                return;
            }

            provider.Enqueue(service, answer);
        }
Ejemplo n.º 2
0
        public static void Enqueue(this ExtendedConcurrentQueue <byte[]> queue, int service, object serviceObject)
        {
            string serviceObjectJSON = ObjectWrapper.Serialize(serviceObject);

            byte[] req = ObjectWrapper.ConvertObjectToByteArray($"{service}|{serviceObjectJSON}");
            lock (queue) queue.Enqueue(req);
        }
Ejemplo n.º 3
0
 public static void GameServerListRequest(ExtendedConcurrentQueue <byte[]> provider)
 {
     try
     {
         lock (LobbyServerObjects.ServerInformationList)
         {
             foreach (GameServerInformation si in LobbyServerObjects.ServerInformationList)
             {
                 provider.Enqueue(NetworkObjectParameters.LobbyServerServerListRequest, si);
             }
         }
     }
     catch (Exception) { }
 }
Ejemplo n.º 4
0
        public static void LoginServiceHUB(ExtendedConcurrentQueue <byte[]> provider, string[] request, Dictionary <int, object> paramDictionary)
        {
            int    service = int.Parse(request[0]);
            object answer  = null;

            switch (service)
            {
            case NetworkObjectParameters.LoginServerLoginAttemptRequest:
                PlayerHandler.StartListeningPlayerLoginAttempt(provider, request[1]);
                return;

            case NetworkObjectParameters.LoginServerAccountCreationRequest:
                answer = PlayerHandler.RegistrationAttempt(request[1]);
                break;
            }

            provider.Enqueue(service, answer);
        }
Ejemplo n.º 5
0
        public static void StartListeningPlayerLoginAttempt(ExtendedConcurrentQueue <byte[]> provider, string param)
        {
            try
            {
                PlayerController pc = new PlayerController();

                Player deserializedPlayer = ObjectWrapper.Deserialize <Player>(param);
                Player player             = pc.LoginPlayer(deserializedPlayer);

                Player answer = null;

                if (player != null)
                {
                    ClientServiceProvider csp = new ClientServiceProvider(
                        NetworkObjectParameters.LobbyServerInformation.ServerLocalAddress,
                        NetworkObjectParameters.LobbyServerInformation.ServerPort,
                        NetworkObjectParameters.LobbyServerBufferSize,
                        (_provider, _request) =>
                    {
                        answer = ObjectWrapper.Deserialize <Player>(_request[1]);
                    });
                    csp.StartOperation();
                    csp.RequestQueue.Enqueue(NetworkObjectParameters.LobbyServerPlayerUIDRequest, player);

                    while (answer == null)
                    {
                        Thread.Sleep(100);
                    }

                    csp.StopOperation();

                    deserializedPlayer.Nickname = answer.Nickname;
                }

                Console.WriteLine($"- Request for: {deserializedPlayer.Nickname} - {deserializedPlayer.Password} - Player " + ((answer == null) ? "not " : "") + "found");

                if (answer == null)
                {
                    provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, null);
                    return;
                }

                // Preparing Player Information Stream
                Dictionary <AvatarCategory, HashSet <int> > ownedAvatars = pc.RetrievePlayerAvatarList(player);

                provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, player);

                if (ownedAvatars != null)
                {
                    foreach (KeyValuePair <AvatarCategory, HashSet <int> > kvp in ownedAvatars)
                    {
                        //For safety reasons, the maximum integer stream size must be 300 integers.
                        const int maximumSize = 300;
                        for (int i = 0; i < kvp.Value.Count; i += maximumSize)
                        {
                            provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, (int)kvp.Key, kvp.Value.Skip(i).Take(maximumSize).ToList());
                        }
                    }
                }

                //Sends the "EOF" to client
                provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, 0, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex}");
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public static void GameServiceHUB(ExtendedConcurrentQueue <byte[]> provider, string[] request, Dictionary <int, object> paramDictionary)
        {
            int    service;
            object answer = null;

            service = (request != null) ? int.Parse(request[0])
                : NetworkObjectParameters.ServerProcessingError;

            PlayerSession playerSession = null;

            if (paramDictionary.ContainsKey(NetworkObjectParameters.PlayerSession))
            {
                playerSession = (PlayerSession)paramDictionary[NetworkObjectParameters.PlayerSession];
            }

            switch (service)
            {
            // Server Information
            case NetworkObjectParameters.GameServerMetadataRequest:
                answer = NetworkObjectParameters.GameServerInformation;
                break;

            // Connection
            case NetworkObjectParameters.GameServerPlayerAccessRequest:
                answer = GameClientProvider.GameServerPlayerAccessRequest(request[1], paramDictionary, provider);
                break;

            // Server Information Request
            case NetworkObjectParameters.GameServerSearchPlayer:
                GameClientProvider.GameServerSearchPlayer(request[1]);
                break;

            // Game List / Requests
            case NetworkObjectParameters.GameServerRoomListCreateRoom:
                answer = GameClientProvider.GameServerRoomListCreateRoom(request[1], playerSession);
                break;

            case NetworkObjectParameters.GameServerRoomListRequestList:
                GameClientProvider.GameServerRoomListRequestList(request[1], provider);
                return;

            case NetworkObjectParameters.GameServerRoomListRoomEnter:
                answer = GameClientProvider.GameServerRoomListRoomEnter(request[1], playerSession);
                break;

            // Game Room / Requests
            case NetworkObjectParameters.GameServerRoomLeaveRoom:
                answer = GameClientProvider.GameServerRoomLeaveRoom(playerSession);
                break;

            case NetworkObjectParameters.GameServerRoomReadyRoom:
                GameClientProvider.GameServerRoomReadyRoom(playerSession);
                return;

            case NetworkObjectParameters.GameServerRoomChangePrimaryMobile:
                GameClientProvider.GameServerRoomChangePrimaryMobile(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerRoomChangeTeam:
                GameClientProvider.GameServerRoomChangeTeam(playerSession);
                return;

            case NetworkObjectParameters.GameServerRoomChangeMap:
                GameClientProvider.GameServerRoomChangeMap(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerRoomRefreshLoadingPercentage:
                GameClientProvider.GameServerRoomRefreshLoadingPercentage(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerRoomStartInGameScene:
                GameClientProvider.GameServerRoomStartInGameScene(playerSession);
                return;

            // InGame / Requests
            case NetworkObjectParameters.GameServerInGameStartMatch:
                GameClientProvider.GameServerInGameStartMatch(playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRefreshSyncMobile:
                GameClientProvider.GameServerInGameRefreshSyncMobile(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRequestNextPlayerTurn:
                answer = GameClientProvider.GameServerInGameRequestNextPlayerTurn(playerSession);
                break;

            case NetworkObjectParameters.GameServerInGameRequestShot:
                GameClientProvider.GameServerInGameRequestShot(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRequestDeath:
                GameClientProvider.GameServerInGameRequestDeath(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRequestItemUsage:
                GameClientProvider.GameServerInGameRequestItemUsage(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRequestDamage:
                GameClientProvider.GameServerInGameRequestDamage(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerInGameRequestLoseTurn:
                GameClientProvider.GameServerInGameRequestLoseTurn(request[1], playerSession);
                return;

            // Messaging / Room List Chat Requests
            case NetworkObjectParameters.GameServerChatEnter:
                GameClientProvider.GameServerChatEnterRequest(request[1], playerSession);
                return;

            case NetworkObjectParameters.GameServerChatLeave:
                GameClientProvider.GameServerChatLeave(playerSession);
                return;

            case NetworkObjectParameters.GameServerChatSendPlayerMessage:
                GameClientProvider.GameServerChatRoomSendMessage(request[1], playerSession);
                return;

            // Avatar Shop
            case NetworkObjectParameters.GameServerAvatarShopBuyAvatarGold:
                answer = GameClientProvider.GameServerAvatarShopBuyAvatar(request[1], playerSession, PaymentMethod.Gold);
                break;

            case NetworkObjectParameters.GameServerAvatarShopBuyAvatarCash:
                answer = GameClientProvider.GameServerAvatarShopBuyAvatar(request[1], playerSession, PaymentMethod.Cash);
                break;

            case NetworkObjectParameters.GameServerAvatarShopUpdatePlayerData:
                GameClientProvider.GameServerAvatarShopUpdatePlayerMetadata(request[1], playerSession);
                return;
            }

            provider.Enqueue(service, answer);
        }