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

                MapInfo mapInfo = mapInfos.Where(m => m.Name == mapName).FirstOrDefault();
                if (mapInfo == null)
                {
                    m_progress.IsVisible = false;
                    m_console.Echo(string.Format("map {0} not found", mapName));
                    return;
                }

                m_gameServer.DownloadMapData(m_gSettings.ClientId, mapInfo.Id, (downloadError, mapData) =>
                {
                    if (m_gameServer.HasError(downloadError))
                    {
                        m_progress.IsVisible = false;
                        OutputError(downloadError);
                        return;
                    }

                    if (m_txtInfo != null)
                    {
                        m_txtInfo.text = mapName;
                    }

                    Debug.Log("lastmap " + mapInfo.Name);
                    PlayerPrefs.SetString("lastmap", mapInfo.Name);
                    Debug.Log(PlayerPrefs.GetString("lastmap"));
                    m_voxelMap.Load(mapData.Bytes, () =>
                    {
                        m_progress.IsVisible = false;
                    });
                });
            });
        }
コード例 #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;
            }
        }