Пример #1
0
        internal VotingJsonData RespondSummaryVote()
        {
            VotingJsonData votingJsonData = null;

            Log.DebugLine("HTTP INFO VOTE", 0);
            var voteCommands = DistanceServerMain.Instance.GetPlugin <VoteCommands.VoteCommands>();

            Log.DebugLine("HTTP INFO VOTE", 1);
            if (voteCommands != null)
            {
                votingJsonData = new VotingJsonData();
                votingJsonData.SkipThreshold   = voteCommands.SkipThreshold;
                votingJsonData.HasSkipped      = voteCommands.HasSkipped;
                votingJsonData.ExtendThreshold = voteCommands.ExtendThreshold;
                votingJsonData.ExtendTime      = voteCommands.ExtendTime;
                votingJsonData.LeftAt          = voteCommands.LeftAt;
                votingJsonData.PlayerVotes     = voteCommands.PlayerVotes;
                votingJsonData.SkipVotes       = voteCommands.SkipVotes.ToArray();
                votingJsonData.ExtendVotes     = voteCommands.ExtendVotes.ToArray();
                var against = new Dictionary <string, int>();
                foreach (var pair in voteCommands.AgainstVotes)
                {
                    against[pair.Key] = pair.Value.Count;
                }
                votingJsonData.AgainstVotes = against;
            }
            return(votingJsonData);
        }
Пример #2
0
        internal void RespondSummary()
        {
            Log.DebugLine("HTTP INFO SUMMARY", 0);
            var server = DistanceServerMain.Instance.Server;
            var writer = new JsonFx.Json.JsonWriter();

            var players = new List <PlayerJsonData>(server.DistancePlayers.Count);

            foreach (var player in server.DistancePlayers.Values)
            {
                var jsonPlayer = new PlayerJsonData();
                jsonPlayer.UnityPlayerGuid        = player.UnityPlayerGuid;
                jsonPlayer.State                  = player.State;
                jsonPlayer.Stuck                  = player.Stuck;
                jsonPlayer.LevelId                = player.LevelId;
                jsonPlayer.ReceivedInfo           = player.ReceivedInfo;
                jsonPlayer.Index                  = player.Index;
                jsonPlayer.Name                   = player.Name;
                jsonPlayer.JoinedAt               = player.JoinedAt;
                jsonPlayer.ValidatedAt            = player.ValidatedAt;
                jsonPlayer.Ready                  = player.Ready;
                jsonPlayer.LevelCompatibilityInfo = player.LevelCompatibilityInfo;
                jsonPlayer.LevelCompatibility     = player.LevelCompatability.ToString();
                jsonPlayer.Valid                  = player.Valid;
                if (IsPrivateMode)
                {
                    jsonPlayer.IpAddress = player.UnityPlayer.ipAddress;
                    jsonPlayer.Port      = player.UnityPlayer.port;
                }
                else
                {
                    jsonPlayer.IpAddress = "Hidden";
                    jsonPlayer.Port      = -1;
                }
                if (player.Car != null)
                {
                    var car     = player.Car;
                    var jsonCar = new CarJsonData();
                    jsonCar.CarColors = new float[][] {
                        new float[] { car.CarColors.primary_.r, car.CarColors.primary_.g, car.CarColors.primary_.b, car.CarColors.primary_.a },
                        new float[] { car.CarColors.secondary_.r, car.CarColors.secondary_.g, car.CarColors.secondary_.b, car.CarColors.secondary_.a },
                        new float[] { car.CarColors.glow_.r, car.CarColors.glow_.g, car.CarColors.glow_.b, car.CarColors.glow_.a },
                        new float[] { car.CarColors.sparkle_.r, car.CarColors.sparkle_.g, car.CarColors.sparkle_.b, car.CarColors.sparkle_.a },
                    };
                    jsonCar.CarName         = car.CarName;
                    jsonCar.Points          = car.Points;
                    jsonCar.Finished        = car.Finished;
                    jsonCar.FinishData      = car.FinishData;
                    jsonCar.FinishType      = car.FinishType;
                    jsonCar.Spectator       = car.Spectator;
                    jsonCar.Alive           = car.Alive;
                    jsonCar.WingsOpen       = car.WingsOpen;
                    jsonCar.Position        = new float[] { car.Rigidbody.position.x, car.Rigidbody.position.y, car.Rigidbody.position.z };
                    jsonCar.Rotation        = new float[] { car.Rigidbody.rotation.w, car.Rigidbody.rotation.x, car.Rigidbody.rotation.y, car.Rigidbody.rotation.z };
                    jsonCar.Velocity        = new float[] { car.Rigidbody.velocity.x, car.Rigidbody.velocity.y, car.Rigidbody.velocity.z };
                    jsonCar.AngularVelocity = new float[] { car.Rigidbody.angularVelocity.x, car.Rigidbody.angularVelocity.y, car.Rigidbody.angularVelocity.z };
                    jsonPlayer.Car          = jsonCar;
                }
                players.Add(jsonPlayer);
            }

            AutoServerJsonData autoServerJson = null;
            var autoServer = DistanceServerMain.Instance.GetPlugin <BasicAutoServer.BasicAutoServer>();

            if (autoServer != null)
            {
                autoServerJson                = new AutoServerJsonData();
                autoServerJson.IdleTimeout    = autoServer.IdleTimeout;
                autoServerJson.LevelTimeout   = autoServer.LevelTimeout;
                autoServerJson.WelcomeMessage = autoServer.WelcomeMessage;
                autoServerJson.AdvanceWhenStartingPlayersFinish = autoServer.AdvanceWhenStartingPlayersFinish;
                autoServerJson.LevelEndTime        = DistanceServerMain.NetworkTimeToUnixTime(autoServer.LevelEndTime);
                autoServerJson.StartingPlayerGuids = autoServer.StartingPlayerGuids.ToArray();
            }

            Log.DebugLine("HTTP INFO SUMMARY", 1);
            VotingJsonData votingJsonData = null;

            try
            {
                votingJsonData = RespondSummaryVote();
            }
            catch (Exception e) { } // TODO
            Log.DebugLine("HTTP INFO SUMMARY", 2);

            var chatLog = new List <ChatJsonData>();

            foreach (var chat in server.ChatLog)
            {
                var chatJson = new ChatJsonData();
                chatJson.Timestamp   = chat.Timestamp;
                chatJson.Chat        = chat.Message;
                chatJson.Sender      = chat.SenderGuid;
                chatJson.Guid        = chat.ChatGuid;
                chatJson.Type        = chat.ChatType.ToString();
                chatJson.Description = chat.ChatDescription;
                chatLog.Add(chatJson);
            }

            Response = writer.Write(new
            {
                Server = new
                {
                    CurrentLevelId               = server.CurrentLevelId,
                    MaxPlayers                   = server.MaxPlayers,
                    Port                         = server.Port,
                    ReportToMasterServer         = server.ReportToMasterServer,
                    MasterServerGameModeOverride = server.MasterServerGameModeOverride,
                    DistanceVersion              = server.DistanceVersion,
                    IsInLobby                    = server.IsInLobby,
                    HasModeStarted               = server.HasModeStarted,
                    ModeStartTime                = DistanceServerMain.NetworkTimeToUnixTime(server.ModeStartTime),
                },
                Level = new
                {
                    Name = server.CurrentLevel.Name,
                    RelativeLevelPath = server.CurrentLevel.RelativeLevelPath,
                    WorkshopFileId    = server.CurrentLevel.WorkshopFileId,
                    GameMode          = server.CurrentLevel.GameMode,
                },
                ChatLog      = chatLog,
                Players      = players,
                AutoServer   = autoServerJson,
                VoteCommands = votingJsonData,
            });
        }