Exemple #1
0
        public EventNatives(string Name)
        {
#if SERVER
            EventsManager = ivmp_server_core.Server.EventsManager;
#endif
            EventsManager.AddEvent(Name);
            Event = EventsManager.GetEvent(Name);
        }
Exemple #2
0
        public EventNatives(string Name)
        {
#if SERVER
            EventsManager = ivmp_server_core.Server.EventsManager;
#endif
            EventsManager.AddEvent(Name);
            Event = EventsManager.GetEvent(Name);
        }
Exemple #3
0
        public static void OnTick(object sender, ElapsedEventArgs e)
        {
            NetIncomingMessage Msg;

            while ((Msg = NetServer.ReadMessage()) != null)
            {
                switch (Msg.MessageType)
                {
                case NetIncomingMessageType.ConnectionApproval:
                    int Version = Msg.ReadInt32();
                    if (Version == Shared.Settings.NetworkVersion)
                    {
                        Msg.SenderConnection.Approve();
                    }
                    else
                    {
                        Msg.SenderConnection.Deny();
                    }
                    break;

                case NetIncomingMessageType.StatusChanged:
                    NetConnectionStatus status = (NetConnectionStatus)Msg.ReadByte();
                    switch (status)
                    {
                    case NetConnectionStatus.Connected:
                    {
                        Player Player = new Player();
                        Player.NetConnection = Msg.SenderConnection;
                        PlayersController.Add(Player);
                        NetOutgoingMessage OutMsg = NetServer.CreateMessage();
                        OutMsg.Write((int)Shared.NetworkMessageType.PlayerConnected);
                        OutMsg.Write(Player.ID);
                        NetServer.SendToAll(OutMsg, Msg.SenderConnection, NetDeliveryMethod.ReliableUnordered, 1);
                        EventsManager.GetEvent("OnPlayerConnected").Trigger(Jint.Native.JsValue.FromObject(Engine, new Scripting.Natives.Player(Player)));
                        foreach (var Resource in ResourcesManager.Resources)
                        {
                            Resource.SendToClient(Player.NetConnection);
                        }
                        break;
                    }

                    case NetConnectionStatus.Disconnected:
                    {
                        Player Player = PlayersController.GetByNetConnection(Msg.SenderConnection);
                        PlayersController.Remove(Player);
                        NetOutgoingMessage OutMsg = NetServer.CreateMessage();
                        OutMsg.Write((int)Shared.NetworkMessageType.PlayerDisconnected);
                        OutMsg.Write(Player.ID);
                        NetServer.SendToAll(OutMsg, Msg.SenderConnection, NetDeliveryMethod.ReliableSequenced, 1);
                        EventsManager.GetEvent("OnPlayerDisconnected").Trigger(Jint.Native.JsValue.FromObject(Engine, new Scripting.Natives.Player(Player)));
                        Player = null;
                        break;
                    }
                    }
                    break;

                case NetIncomingMessageType.DebugMessage:
                    break;

                case NetIncomingMessageType.WarningMessage:
                    break;

                case NetIncomingMessageType.Data:
                    int MsgType = Msg.ReadInt32();
                    switch (MsgType)
                    {
                    case (int)Shared.NetworkMessageType.UpdatePlayer:
                        PlayerUpdateStruct PlayerData = new PlayerUpdateStruct();
                        Msg.ReadAllFields(PlayerData);
                        Player Player = PlayersController.GetByNetConnection(Msg.SenderConnection);
                        Player.Name   = PlayerData.Name;
                        Player.Health = PlayerData.Health;
                        Player.Armor  = PlayerData.Armor;
                        Vector3 Position = new Vector3();
                        Position.X = PlayerData.Pos_X;
                        Position.Y = PlayerData.Pos_Y;
                        Position.Z = PlayerData.Pos_Z;
                        Vector3 Velocity = new Vector3();
                        Velocity.X = PlayerData.Vel_X;
                        Velocity.Y = PlayerData.Vel_Y;
                        Velocity.Z = PlayerData.Vel_Z;
                        Quaternion Rotation = new Quaternion();
                        Rotation.X = PlayerData.Rot_X;
                        Rotation.Y = PlayerData.Rot_Y;
                        Rotation.Z = PlayerData.Rot_Z;
                        Rotation.W = PlayerData.Rot_A;
                        if (PlayerData.CurrentVehicle > 0)
                        {
                            Vehicle Vehicle = VehiclesController.GetByID(PlayerData.CurrentVehicle);
                            Vehicle.Position      = Position;
                            Vehicle.Velocity      = Velocity;
                            Vehicle.Rotation      = Rotation;
                            Vehicle.Heading       = PlayerData.Heading;
                            Vehicle.Speed         = PlayerData.Speed;
                            Vehicle.Driver        = Player;
                            Player.CurrentVehicle = PlayerData.CurrentVehicle;
                            Player.VehicleSeat    = PlayerData.VehicleSeat;
                        }
                        else
                        {
                            if (Player.CurrentVehicle > 0)
                            {
                                Vehicle Vehicle = VehiclesController.GetByID(Player.CurrentVehicle);
                                Vehicle.Driver        = null;
                                Player.CurrentVehicle = 0;
                            }
                            Player.Position              = Position;
                            Player.Velocity              = Velocity;
                            Player.Heading               = PlayerData.Heading;
                            Player.IsWalking             = PlayerData.IsWalking;
                            Player.IsRunning             = PlayerData.IsRunning;
                            Player.IsJumping             = PlayerData.IsJumping;
                            Player.IsCrouching           = PlayerData.IsCrouching;
                            Player.IsGettingIntoVehicle  = PlayerData.IsGettingIntoVehicle;
                            Player.IsGettingOutOfVehicle = PlayerData.IsGettingOutOfVehicle;
                        }

                        // Test Player

                        if (TestPlayer != null)
                        {
                            TestPlayer.Name   = "TestPlayer";
                            TestPlayer.Health = PlayerData.Health;
                            TestPlayer.Armor  = PlayerData.Armor;
                            Position.X        = Position.X + 5;
                            if (PlayerData.CurrentVehicle > 0)
                            {
                                if (PlayerData.CurrentVehicle == 1)
                                {
                                    PlayerData.CurrentVehicle = 2;
                                }
                                Vehicle Vehicle = VehiclesController.GetByID(PlayerData.CurrentVehicle);
                                Vehicle.Position          = Position;
                                Vehicle.Velocity          = Velocity;
                                Vehicle.Rotation          = Rotation;
                                Vehicle.Heading           = PlayerData.Heading;
                                Vehicle.Speed             = PlayerData.Speed;
                                Vehicle.Driver            = TestPlayer;
                                TestPlayer.CurrentVehicle = PlayerData.CurrentVehicle;
                                TestPlayer.VehicleSeat    = PlayerData.VehicleSeat;
                            }
                            else
                            {
                                if (TestPlayer.CurrentVehicle > 0)
                                {
                                    Vehicle Vehicle = VehiclesController.GetByID(TestPlayer.CurrentVehicle);
                                    Vehicle.Driver            = null;
                                    TestPlayer.CurrentVehicle = 0;
                                }
                                TestPlayer.Position              = Position;
                                TestPlayer.Velocity              = Velocity;
                                TestPlayer.Heading               = PlayerData.Heading;
                                TestPlayer.IsWalking             = PlayerData.IsWalking;
                                TestPlayer.IsRunning             = PlayerData.IsRunning;
                                TestPlayer.IsJumping             = PlayerData.IsJumping;
                                TestPlayer.IsCrouching           = PlayerData.IsCrouching;
                                TestPlayer.IsGettingIntoVehicle  = PlayerData.IsGettingIntoVehicle;
                                TestPlayer.IsGettingOutOfVehicle = PlayerData.IsGettingOutOfVehicle;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    Console.WriteLine("Unhandled message type: " + Msg.MessageType);
                    break;
                }
                NetServer.Recycle(Msg);
            }

            UpdateAllPlayers();
            UpdateAllVehicles();
        }