Exemplo n.º 1
0
        /// <summary>
        ///     Send colors to server if not default colors.
        /// </summary>
        private void SendColors()
        {
            var player = MyAPIGateway.Session.LocalHumanPlayer;

            if (player == null)
            {
                return;
            }

            var colors = player.BuildColorSlots;

            if (!colors.SequenceEqual(_lastColorsSend))
            {
                var message = new BuildColorMessage {
                    BuildColors = colors,
                    SteamId     = player.SteamUserId
                };

                Network.SendToServer(message);

                _lastColorsSend.Clear();
                _lastColorsSend.AddRange(colors);
                _lasTimeColorChecked = DateTime.UtcNow;
            }
        }
Exemplo n.º 2
0
        private void OnBuildColorsReceived(ulong sender, BuildColorMessage message)
        {
            if (Network.IsClient)
            {
                var player = MyAPIGateway.Session.LocalHumanPlayer;
                if (player != null && player.SteamUserId == message.SteamId && message.BuildColors != null && message.BuildColors.Any())
                {
                    player.BuildColorSlots = message.BuildColors;
                    _lastColorsSend.Clear();
                    _lastColorsSend.AddRange(player.BuildColorSlots);
                }
            }
            else if (Network.IsServer)
            {
                var playerColor = new PlayerColors {
                    Id = message.SteamId, Colors = MyAPIGateway.Utilities.SerializeToBinary(message.BuildColors)
                };
                if (Settings.Colors.Contains(playerColor))
                {
                    Settings.Colors.Remove(playerColor);
                }

                Settings.Colors.Add(playerColor);
            }
        }
Exemplo n.º 3
0
        private void OnBuilderColorRequest(ulong sender, RequestBuildColors message)
        {
            var data = Settings.Colors.FirstOrDefault(x => x.Id == message.SteamId).Colors;

            if (data == null)
            {
                return;
            }

            try {
                var colors   = MyAPIGateway.Utilities.SerializeFromBinary <List <Vector3> >(data);
                var response = new BuildColorMessage {
                    BuildColors = colors,
                    SteamId     = message.SteamId
                };

                Network.Send(response, sender);
            } catch (Exception exception) {
                throw new Exception("Unable to create response.", exception);
            }
        }