protected override void OnRequest(ILowProtocol sender, LowRequestArgs request)
        {
            RemoteCall rpc;

            try
            {
                rpc = m_serializer.Deserialize <RemoteCall>(request.Data);
            }
            catch (Exception e)
            {
                Log.Error("Invalid RemoteCall format ", e);

                //#warning Should force disconnect client
                #warning This code is not tested
                sender.Disable();

                throw;
            }


            switch (rpc.Procedure)
            {
            case RemoteCall.Proc.RegisterClient:
            {
                RegisterClient(sender, rpc.ClientId);
                Return(sender, request, new Error(StatusCode.OK));
            }
            break;

            case RemoteCall.Proc.GetPlayers:
                m_gameServer.GetPlayers(rpc.ClientId, (error, players) =>
                {
                    Return(sender, request, error, RemoteArg.Create(players));
                });
                break;

            case RemoteCall.Proc.GetPlayersByRoomId:
                m_gameServer.GetPlayers(rpc.ClientId, rpc.Get <Guid>(0), (error, players) =>
                {
                    Return(sender, request, error, RemoteArg.Create(players));
                });
                break;

            case RemoteCall.Proc.GetPlayer:
                m_gameServer.GetPlayer(rpc.ClientId, rpc.Get <Guid>(0), (error, players) =>
                {
                    Return(sender, request, error, RemoteArg.Create(players));
                });
                break;

            case RemoteCall.Proc.Login:
                m_gameServer.Login(rpc.Get <string>(0), rpc.Get <string>(1), rpc.ClientId, (error, playerId, pwdHash) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(pwdHash));
                });
                break;

            case RemoteCall.Proc.LoginHash:
                m_gameServer.Login(rpc.Get <string>(0), rpc.Get <byte[]>(1), rpc.ClientId, (error, playerId) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerId));
                });
                break;

            case RemoteCall.Proc.SignUp:
                m_gameServer.SignUp(rpc.Get <string>(0), rpc.Get <string>(1), rpc.ClientId, (error, playerId, pwdHash) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(pwdHash));
                });
                break;

            case RemoteCall.Proc.Logoff:
                m_gameServer.Logoff(rpc.ClientId, rpc.Get <Guid>(0), (error, guid) =>
                {
                    Return(sender, request, error, RemoteArg.Create(guid));
                });
                break;

            case RemoteCall.Proc.LogoffMultiple:
                m_gameServer.Logoff(rpc.ClientId, rpc.Get <Guid[]>(0), (error, guids) =>
                {
                    Return(sender, request, error, RemoteArg.Create(guids));
                });
                break;

            case RemoteCall.Proc.JoinRoom:
                m_gameServer.JoinRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, room) =>
                {
                    //Boradcast to room players
                    Return(sender, request, error, RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.LeaveRoom:
                m_gameServer.LeaveRoom(rpc.ClientId, (error) =>
                {
                    //Brodcast to room players
                    Return(sender, request, error);
                });
                break;

            case RemoteCall.Proc.GetRooms:
                m_gameServer.GetRooms(rpc.ClientId, rpc.Get <int>(0), rpc.Get <int>(1), (error, rooms) =>
                {
                    Return(sender, request, error, RemoteArg.Create(rooms));
                });
                break;

            case RemoteCall.Proc.GetRoom:
                m_gameServer.GetRoom(rpc.ClientId, (error, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.GetRoomById:
                m_gameServer.GetRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.CreateRoom:
                m_gameServer.CreateRoom(rpc.ClientId, rpc.Get <Guid>(0), rpc.Get <GameMode>(1), (error, room) =>
                {
                    //Do not broadcast
                    //client will get rooms list using polling each 10 seconds
                    //or using refres button
                    Return(sender, request, error, RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.DestroyRoom:
                m_gameServer.DestroyRoom(rpc.ClientId, rpc.Get <Guid>(0), (error, guid) =>
                {
                    Return(sender, request, error, RemoteArg.Create(guid));
                });
                break;

            case RemoteCall.Proc.CreateBot:
                m_gameServer.CreateBot(rpc.ClientId, rpc.Get <string>(0), rpc.Get <BotType>(1), (error, playerId, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.CreateBots:
                m_gameServer.CreateBots(rpc.ClientId, rpc.Get <string[]>(0), rpc.Get <int[]>(1).ToEnum <BotType>(), (error, playerIds, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerIds), RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.DestroyBot:
                m_gameServer.DestroyBot(rpc.ClientId, rpc.Get <Guid>(0), (error, playerId, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(playerId), RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.UploadMapData:
                m_gameServer.UploadMap(rpc.ClientId, rpc.Get <MapInfo>(0), rpc.Get <byte[]>(1), (error) =>
                {
                    Return(sender, request, error);
                });
                break;

            case RemoteCall.Proc.GetMaps:
                m_gameServer.GetMaps(rpc.ClientId, (Error error, ByteArray[] mapsInfo) =>
                {
                    Return(sender, request, error, RemoteArg.Create(mapsInfo));
                });
                break;

            case RemoteCall.Proc.DownloadMapData:
                m_gameServer.DownloadMapData(rpc.ClientId, rpc.Get <Guid>(0), (Error error, byte[] mapData) =>
                {
                    Return(sender, request, error, RemoteArg.Create(mapData));
                });
                break;

            case RemoteCall.Proc.GetReplays:
                m_gameServer.GetReplays(rpc.ClientId, (Error error, ByteArray[] replaysInfo) =>
                {
                    Return(sender, request, error, RemoteArg.Create(replaysInfo));
                });
                break;

            case RemoteCall.Proc.SetReplay:
                m_gameServer.SetReplay(rpc.ClientId, rpc.Get <Guid>(0), (error) =>
                {
                    Return(sender, request, error);
                });
                break;

            case RemoteCall.Proc.SaveReplay:
                m_gameServer.SaveReplay(rpc.ClientId, rpc.Get <string>(0), (error) =>
                {
                    Return(sender, request, error);
                });
                break;

            case RemoteCall.Proc.GetStats:
                m_gameServer.GetStats(rpc.ClientId, (error, serverStats) =>
                {
                    Return(sender, request, error, RemoteArg.Create(serverStats));
                });
                break;

            case RemoteCall.Proc.SetReadyToLaunch:
                m_gameServer.SetReadyToLaunch(rpc.ClientId, rpc.Get <bool>(0), (error, room) =>
                {
                    Return(sender, request, error, RemoteArg.Create(room));
                });
                break;

            case RemoteCall.Proc.Launch:
                m_gameServer.Launch(rpc.ClientId, (error, serverUrl) =>
                {
                    Return(sender, request, error, RemoteArg.Create(serverUrl));
                });
                break;

            case RemoteCall.Proc.SendChatMessage:
                m_gameServer.SendMessage(rpc.ClientId, rpc.Get <ChatMessage>(0), (error, messageId) =>
                {
                    Return(sender, request, error, RemoteArg.Create(messageId));
                });
                break;
            }
        }
Пример #2
0
        private static void InitGame(string mapName, int playerIndex, int botIndex, int playersCount, int botsCount, Action callback, Action <Error> error)
        {
            //IProgressIndicator progress = Dependencies.Progress;
            IGameServer     server    = Dependencies.GameServer;
            IGlobalSettings gSettings = Dependencies.Settings;


            if (playerIndex < playersCount)
            {
                server.Login(m_playerNames[playerIndex], "welcome", gSettings.ClientId, (e1, playerId, pwdHash) =>
                {
                    if (server.HasError(e1))
                    {
                        error(e1);
                        //progress.IsVisible = false;
                        server.SignUp(m_playerNames[playerIndex], "welcome", gSettings.ClientId, (e100, p, pwdHash2) =>
                        {
                            if (server.HasError(e100))
                            {
                                error(e100);
                                //progress.IsVisible = false;
                                return;
                            }

                            LoginOrSignupCompleted(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error);
                        });
                    }
                    else
                    {
                        LoginOrSignupCompleted(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error);
                    }
                });
            }
            else
            {
                if (botIndex == botsCount)
                {
                    Launch(mapName, callback, error, null, /*progress*/ server, gSettings);
                }
                else
                {
                    server.CreateBot(gSettings.ClientId, m_playerNames[playersCount + botIndex], BotType.Hard, (e4, botId, roomWithBot) =>
                    {
                        if (server.HasError(e4))
                        {
                            error(e4);
                            //progress.IsVisible = false;
                            return;
                        }

                        botIndex++;

                        if (botIndex == botsCount)
                        {
                            Launch(mapName, callback, error, null /*progress*/, server, gSettings);
                        }
                        else
                        {
                            InitGame(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error);
                        }
                    });
                }
            }
        }