Beispiel #1
0
        private void SpawnedGridsSuccessful(HashSet <MyCubeGrid> Grids)
        {
            GridUtilities.BiggestGrid(Grids, out MyCubeGrid BiggestGrid);

            if (BiggestGrid != null && IdentityID != 0)
            {
                GpsSender.SendGps(BiggestGrid.PositionComp.GetPosition(), BiggestGrid.DisplayName, IdentityID);
            }
        }
        private static void ReceivePacket(ushort HandlerId, byte[] Data, ulong SteamID, bool FromServer)
        {
            // Only consider trusted server messages, i.e. from Nexus itself, not untrusted player messages.
            if (!FromServer)
            {
                return;
            }

            NexusHangarMessage msg;

            try
            {
                msg = MyAPIGateway.Utilities.SerializeFromBinary <NexusHangarMessage>(Data);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Invalid Nexus cross-server message for Quantum Hangar");
                return;
            }

            switch (msg.Type)
            {
            case NexusHangarMessageType.Chat:
                var chat = new ScriptedChatMsg()
                {
                    Author = msg.Sender,
                    Text   = msg.Response,
                    Font   = MyFontEnum.White,
                    Color  = msg.Color,
                    Target = msg.ChatIdentityID
                };
                MyMultiplayerBase.SendScriptedChatMessage(ref chat);
                return;

            case NexusHangarMessageType.SendGPS:
                gpsSender.SendGps(msg.Position, msg.Name, msg.EntityID);
                return;

            case NexusHangarMessageType.LoadGrid:
                var chatOverNexus = new Chat((text, color, sender) =>
                {
                    NexusHangarMessage m = new NexusHangarMessage
                    {
                        Type       = NexusHangarMessageType.Chat,
                        IdentityID = msg.IdentityID,
                        Response   = text,
                        Color      = color,
                        Sender     = sender,
                    };
                    API.SendMessageToServer(msg.ServerID, MyAPIGateway.Utilities.SerializeToBinary <NexusHangarMessage>(m));
                });

                var gpsOverNexus = new GpsSender((position, name, entityID) =>
                {
                    NexusHangarMessage m = new NexusHangarMessage
                    {
                        Type     = NexusHangarMessageType.SendGPS,
                        Name     = name,
                        Position = position,
                        EntityID = entityID,
                    };
                    API.SendMessageToServer(msg.ServerID, MyAPIGateway.Utilities.SerializeToBinary <NexusHangarMessage>(m));
                });

                PlayerChecks User = new PlayerChecks(chatOverNexus, gpsOverNexus, msg.SteamID, msg.IdentityID, msg.PlayerPosition);


                User.LoadGrid(msg.LoadGridID.ToString(), msg.LoadNearPlayer);
                return;
            }

            Log.Error("Invalid Nexus cross-server message for Quantum Hangar (unrecognized type: " + msg.Type + ")");
        }