Ejemplo n.º 1
0
            public override void ProcessPacket(ReturnItemsPacket packet, INebulaConnection conn)
            {
                List <ItemPackageL> items = packet.GetData();

                foreach (ItemPackageL item in items)
                {
                    int upCount = GameMain.mainPlayer.TryAddItemToPackage(item.item, item.stack, item.stack, true);
                    UIItemup.Up(item.item, upCount);
                }
            }
Ejemplo n.º 2
0
 public override void ProcessPacket(ClearUndoRequestPacket packet, INebulaConnection conn)
 {
     if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
     {
         PlayerUndo data = UndoManager.GetPlayerData(packet.AuthorId);
         using (NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.On())
         {
             data.ResetUndo();
         }
     }
 }
Ejemplo n.º 3
0
        public override void ProcessPacket(ReformPasteEventPacket packet, INebulaConnection conn)
        {
            PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);

            if (planet.factory == null)
            {
                return;
            }

            PlayerAction_Build       pab       = GameMain.mainPlayer.controller != null ? GameMain.mainPlayer.controller.actionBuild : null;
            BuildTool_BlueprintPaste buildTool = pab.blueprintPasteTool;

            IFactoryManager factoryManager = NebulaModAPI.MultiplayerSession.Factories;

            if (buildTool == null)
            {
                return;
            }

            factoryManager.TargetPlanet = packet.PlanetId;
            factoryManager.PacketAuthor = packet.AuthorId;

            PlanetFactory tmpFactory             = null;
            bool          loadExternalPlanetData = GameMain.localPlanet?.id != planet.id;

            if (loadExternalPlanetData)
            {
                tmpFactory = buildTool.factory;
                factoryManager.AddPlanetTimer(packet.PlanetId);
            }

            factoryManager.EventFactory = planet.factory;

            buildTool.factory = planet.factory;
            pab.factory       = planet.factory;

            using (factoryManager.IsIncomingRequest.On())
            {
                packet.GetData(out List <ReformData> reforms, out Color[] colors);
                BlueprintPasteExtension.CalculatePositions(buildTool, reforms, colors);
            }

            if (loadExternalPlanetData)
            {
                buildTool.factory = tmpFactory;
                pab.factory       = tmpFactory;
            }

            GameMain.mainPlayer.mecha.buildArea = Configs.freeMode.mechaBuildArea;
            factoryManager.EventFactory         = null;

            factoryManager.TargetPlanet = NebulaModAPI.PLANET_NONE;
            factoryManager.PacketAuthor = NebulaModAPI.AUTHOR_NONE;
        }
Ejemplo n.º 4
0
        public INebulaPlayer GetSyncingPlayer(INebulaConnection conn)
        {
            using (GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
            {
                if (syncingPlayers.TryGetValue(conn, out INebulaPlayer player))
                {
                    return(player);
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
 public void SendRawPacketToPlanet(byte[] rawPacket, int planetId, INebulaConnection sender)
 {
     using (GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
     {
         foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers)
         {
             INebulaPlayer player = kvp.Value;
             if (player.Data.LocalPlanetId == planetId && (NebulaConnection)player.Connection != (NebulaConnection)sender)
             {
                 ((NebulaPlayer)player).SendRawPacket(rawPacket);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void SendPacketToStarExcept <T>(T packet, int starId, INebulaConnection exclude) where T : class, new()
 {
     using (GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
     {
         foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers)
         {
             INebulaPlayer player = kvp.Value;
             if (player.Data.LocalStarId == starId && player != GetPlayer(exclude))
             {
                 player.SendPacket(packet);
             }
         }
     }
 }
Ejemplo n.º 7
0
        public INebulaPlayer PlayerConnected(INebulaConnection conn)
        {
            // Generate new data for the player
            ushort playerId = GetNextAvailablePlayerId();

            PlanetData birthPlanet = GameMain.galaxy.PlanetById(GameMain.galaxy.birthPlanetId);
            PlayerData playerData  = new PlayerData(playerId, -1, Config.Options.GetMechaColors(), position: new Double3(birthPlanet.uPosition.x, birthPlanet.uPosition.y, birthPlanet.uPosition.z));

            INebulaPlayer newPlayer = new NebulaPlayer((NebulaConnection)conn, playerData);

            using (GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
            {
                pendingPlayers.Add(conn, newPlayer);
            }

            return(newPlayer);
        }
Ejemplo n.º 8
0
 public void UpdateMechaData(IMechaData mechaData, INebulaConnection conn)
 {
     if (mechaData == null)
     {
         return;
     }
     using (GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
     {
         if (connectedPlayers.TryGetValue(conn, out INebulaPlayer player))
         {
             //Find correct player for data to update, preserve sand count if syncing is enabled
             int sandCount = player.Data.Mecha.SandCount;
             player.Data.Mecha = mechaData;
             if (Config.Options.SyncSoil)
             {
                 player.Data.Mecha.SandCount = sandCount;
             }
         }
     }
 }
Ejemplo n.º 9
0
 public abstract void SendPacketToStarExclude <T>(T packet, int starId, INebulaConnection exclude)
     where T : class, new();
Ejemplo n.º 10
0
        public void PlayerDisconnected(INebulaConnection conn)
        {
            INebulaPlayer player           = null;
            bool          playerWasSyncing = false;
            int           syncCount        = -1;

            Multiplayer.Session.NumPlayers -= 1;
            DiscordManager.UpdateRichPresence();

            using (GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
            {
                if (connectedPlayers.TryGetValue(conn, out INebulaPlayer removingPlayer))
                {
                    player = removingPlayer;
                    connectedPlayers.Remove(conn);
                }
            }

            using (GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers))
            {
                if (pendingPlayers.TryGetValue(conn, out INebulaPlayer removingPlayer))
                {
                    player = removingPlayer;
                    pendingPlayers.Remove(conn);
                }
            }

            using (GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers))
            {
                if (syncingPlayers.TryGetValue(conn, out INebulaPlayer removingPlayer))
                {
                    player = removingPlayer;
                    syncingPlayers.Remove(conn);
                    playerWasSyncing = true;
                    syncCount        = syncingPlayers.Count;
                }
            }

            if (player != null)
            {
                SendPacketToOtherPlayers(new PlayerDisconnected(player.Id, Multiplayer.Session.NumPlayers), player);
                NebulaModAPI.OnPlayerLeftGame?.Invoke(player.Data);
                Multiplayer.Session.World.DestroyRemotePlayerModel(player.Id);
                using (threadSafe.availablePlayerIds.GetLocked(out Queue <ushort> availablePlayerIds))
                {
                    availablePlayerIds.Enqueue(player.Id);
                }
                Multiplayer.Session.Statistics.UnRegisterPlayer(player.Id);
                Multiplayer.Session.DysonSpheres.UnRegisterPlayer(conn);

                //Notify players about queued building plans for drones
                int[] DronePlans = Multiplayer.Session.Drones.GetPlayerDronePlans(player.Id);
                if (DronePlans != null && DronePlans.Length > 0 && player.Data.LocalPlanetId > 0)
                {
                    Multiplayer.Session.Network.SendPacketToPlanet(new RemoveDroneOrdersPacket(DronePlans), player.Data.LocalPlanetId);
                    //Remove it also from host queue, if host is on the same planet
                    if (GameMain.mainPlayer.planetId == player.Data.LocalPlanetId)
                    {
                        for (int i = 0; i < DronePlans.Length; i++)
                        {
                            GameMain.mainPlayer.mecha.droneLogic.serving.Remove(DronePlans[i]);
                        }
                    }
                }

                if (playerWasSyncing && syncCount == 0)
                {
                    Multiplayer.Session.Network.SendPacket(new SyncComplete());
                    Multiplayer.Session.World.OnAllPlayersSyncCompleted();
                }
                else if (Config.Options.SyncSoil)
                {
                    GameMain.mainPlayer.sandCount -= player.Data.Mecha.SandCount;
                    UIRoot.instance.uiGame.OnSandCountChanged(GameMain.mainPlayer.sandCount, -player.Data.Mecha.SandCount);
                    Multiplayer.Session.Network.SendPacket(new PlayerSandCount(GameMain.mainPlayer.sandCount));
                }
            }
            else
            {
                Log.Warn($"PlayerDisconnected NOT CALLED!");

                if (Config.Options.SyncSoil)
                {
                    // now we need to recalculate the current sand amount :C
                    GameMain.mainPlayer.sandCount = Multiplayer.Session.LocalPlayer.Data.Mecha.SandCount;
                    using (GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers))
                    {
                        foreach (KeyValuePair <INebulaConnection, INebulaPlayer> entry in connectedPlayers)
                        {
                            GameMain.mainPlayer.sandCount += entry.Value.Data.Mecha.SandCount;
                        }
                    }
                    UIRoot.instance.uiGame.OnSandCountChanged(GameMain.mainPlayer.sandCount, GameMain.mainPlayer.sandCount - Multiplayer.Session.LocalPlayer.Data.Mecha.SandCount);
                    Multiplayer.Session.Network.SendPacket(new PlayerSandCount(GameMain.mainPlayer.sandCount));
                }
            }
        }
Ejemplo n.º 11
0
 public override void ProcessPacket(T packet, INebulaConnection conn)
 {
     ProcessPacket(packet, (NebulaConnection)conn);
 }
Ejemplo n.º 12
0
 public override void SendPacketToStarExclude <T>(T packet, int starId, INebulaConnection exclude)
 {
     // Only possible from host
     throw new System.NotImplementedException();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Process packets here
 /// </summary>
 /// <param name="packet">Received packet</param>
 /// <param name="conn">Connection that sent the packet</param>
 public abstract void ProcessPacket(T packet, INebulaConnection conn);
Ejemplo n.º 14
0
 public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, FastRemoveRequestPacket packet, INebulaConnection conn)
 {
     if (packet.UseEdgeVariant)
     {
         FastRemoveHelper.SwitchDelete(factory, packet.ObjIds.ToList(), packet.EdgeObjIds.ToList());
     }
     else
     {
         FastRemoveHelper.SwitchDelete(factory, packet.ObjIds.ToList());
     }
 }
Ejemplo n.º 15
0
 public override void ProcessPacket(ActionResultPacket packet, INebulaConnection conn)
 {
     UIRealtimeTip.Popup(packet.message.Translate(), packet.sound);
 }
Ejemplo n.º 16
0
 public override void SendPacketToStarExclude <T>(T packet, int starId, INebulaConnection exclude)
 {
     PlayerManager.SendPacketToStarExcept(packet, starId, (NebulaConnection)exclude);
 }
Ejemplo n.º 17
0
            public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, RedoRequestPacket packet, INebulaConnection conn)
            {
                INebulaPlayer player = NebulaModAPI.MultiplayerSession.Network.PlayerManager.GetPlayer(conn);

                if (UndoManager.undos[player.Id].TryRedo(out string message, out bool sound))
                {
                    conn.SendPacket(new ActionResultPacket(message, sound));
                }
            }