コード例 #1
0
        private void OnUploadMap(string mapName, int maxPlayers)
        {
            m_progress.IsVisible = true;
            m_gameServer.GetMaps(m_gSettings.ClientId, (error, mapInfos) =>
            {
                if (m_gameServer.HasError(error))
                {
                    m_progress.IsVisible = false;
                    OutputError(error);
                    return;
                }

                m_voxelMap.Save(bytes =>
                {
                    MapInfo mapInfo = mapInfos.Where(m => m.Name == mapName).FirstOrDefault();
                    if (mapInfo == null)
                    {
                        Guid mapId = Guid.NewGuid();

                        mapInfo = new MapInfo
                        {
                            Id             = mapId,
                            Name           = mapName,
                            MaxPlayers     = maxPlayers,
                            SupportedModes = GameMode.All
                        };
                    }
                    else
                    {
                        mapInfo.MaxPlayers     = maxPlayers;
                        mapInfo.SupportedModes = GameMode.All;
                    }

                    MapData mapData = new MapData
                    {
                        Id    = mapInfo.Id,
                        Bytes = bytes,
                    };

                    m_gameServer.UploadMap(m_gSettings.ClientId, mapInfo, mapData, uploadError =>
                    {
                        m_progress.IsVisible = false;
                        if (m_gameServer.HasError(uploadError))
                        {
                            OutputError(uploadError);
                        }
                    });
                });
            });
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        private static void LoginOrSignupCompleted(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;

            playerIndex++;

            if (playerIndex == playersCount)
            {
                server.GetMaps(gSettings.ClientId, (e2, maps) =>
                {
                    if (server.HasError(e2))
                    {
                        error(e2);
                        // progress.IsVisible = false;
                        return;
                    }

                    MapInfo mapInfo;
                    if (!string.IsNullOrEmpty(mapName))
                    {
                        mapInfo = maps.Where(m => m.Name == mapName).FirstOrDefault();

                        if (mapInfo == null)
                        {
                            Debug.Log(mapName + " not found. Searching for default map..");
                            mapName = "Default";
                            mapInfo = maps.Where(m => m.Name == mapName).FirstOrDefault();
                            if (mapInfo != null)
                            {
                                Debug.Log("Default map found");
                            }
                        }
                    }
                    else
                    {
                        mapInfo = PlayerPrefs.HasKey("lastmap") ? maps.Where(m => m.Name == PlayerPrefs.GetString("lastmap")).FirstOrDefault() : maps.FirstOrDefault();

                        if (mapInfo == null)
                        {
                            mapInfo = maps.FirstOrDefault();
                        }
                    }

                    if (mapInfo == null)
                    {
                        Debug.LogWarning("No maps. Creating Default map...");
                        CreateDefaultMap((createDefaultError, defaultMapInfo) =>
                        {
                            if (server.HasError(createDefaultError))
                            {
                                error(createDefaultError);
                                //progress.IsVisible = false;
                                return;
                            }

                            mapName = defaultMapInfo.Name;
                            mapInfo = defaultMapInfo;
                            CreateRoom(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error, null /*progress*/, server, gSettings, mapInfo);
                        });
                    }
                    else
                    {
                        mapName = mapInfo.Name;
                        CreateRoom(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error, null /*progress*/, server, gSettings, mapInfo);
                    }
                });
            }
            else
            {
                InitGame(mapName, playerIndex, botIndex, playersCount, botsCount, callback, error);
            }
        }