public ServerUDPTunnel(ServerPlayer player)
 {
     // enstablish an Connection
     this.player = player;
     udp = new UdpClient(new IPEndPoint(IPAddress.Any, Server.instance.UDPStartPort + (int)player.id));
     udp.BeginReceive(onReceive, null);
 }
        public void flush()
        {
            lock (this.Connection)
            {
                try
                {
                    var stream = this.Connection.GetStream();
                    this.InternalBuffer.InsertRange(0, BitConverter.GetBytes((int)(InternalBuffer.Count + 4)));
                    stream.Write(this.InternalBuffer.ToArray(), 0, this.InternalBuffer.Count);
                    stream.Flush();
                    InternalBuffer = new List<byte>();
                }
                catch
                {
                    if (Player != null)
                    {
                        Server.instance.api.invokeOnPlayerDisconnect(Player);

                        Player.data = null;
                        Server.instance.playerpool.Remove(Player);
                        Player = null;
                    }
                }
            }
        }
 public void show(ServerPlayer player)
 {
     var bpf = new BinaryPacketFormatter(Commands.NPCDialog_show);
     bpf.Add(id);
     bpf.Add(caption);
     bpf.Add(text);
     bpf.Add(String.Join("\x01", responses.ToArray()));
     player.connection.write(bpf.getBytes());
 }
        public TextView(ServerPlayer player, string text, float fontsize, Point position)
        {
            if (textviewspool == null) textviewspool = new Dictionary<uint, TextView>();
            this.text = text;
            this.size = fontsize;
            this.position = position;
            this.player = player;
            id = findLowestFreeId();
            textviewspool.Add(id, this);

            var bpf = new BinaryPacketFormatter(Commands.TextView_create);
            bpf.Add(id);
            bpf.Add(size);
            bpf.Add(position.X);
            bpf.Add(position.Y);
            bpf.Add(text);
            player.connection.write(bpf.getBytes());
        }
Esempio n. 5
0
 public void broadcastData(ServerPlayer player)
 {
     if (player.data.client_has_been_set) return;
     else player.data.client_has_been_set = true;
     try
     {
         if (player.data != null)
         {
             InvokeParallelForEachPlayer((single) =>
             {
                 if (single.id != player.id)
                 {
                     var bpf = new BinaryPacketFormatter(Commands.UpdateData);
                     bpf.Add(player.id);
                     bpf.Add(player.data);
                     single.connection.write(bpf.getBytes());
                     //Console.WriteLine("Streaming to Player " + single.Value.nick);
                 }
             });
         }
     }
     catch (Exception e) { Console.WriteLine(e); }
 }
 private void api_onPlayerSendText(ServerPlayer player, string text)
 {
     api.writeChat(player.Nick + "(" + player.id + "): " + text);
     Console.WriteLine("# " + player.Nick + " [" + player.id + "]: " + text);
     player.CurrentPedText = text;
     if(lasttexttimer != null && lasttexttimer.Enabled) lasttexttimer.Stop();
     lasttexttimer = after(2500, delegate
     {
         player.CurrentPedText = "";
     });
 }
Esempio n. 7
0
 public void broadcastVehiclesToPlayer(ServerPlayer player)
 {
     foreach (var pair in vehicleController.vehicles)
     {
         var bpf = new BinaryPacketFormatter(Commands.Vehicle_create);
         bpf.Add(pair.Value.id);
         bpf.Add(pair.Value.position);
         bpf.Add(pair.Value.orientation);
         bpf.Add(ModelDictionary.getVehicleByName(pair.Value.model));
         player.connection.write(bpf.getBytes());
     }
 }
 public ServerRequester(ServerPlayer player)
 {
     this.player = player;
 }
 private void api_onPlayerSpawn(ServerPlayer player)
 {
     api.writeChat("Player " + player.Nick + " spawned");
     if (((PlayerData)player.metadata).inSkinSelectionMode)
     {
         player.Camera.Position = skinCameraPos;
         player.Camera.LookAt(skinPedPos);
         player.Position = skinPedPos;
         player.Heading = 242.1461f;
         player.Freezed = true;
         player.VirtualWorld = 1;
         player.Model = ModelDictionary.getAllPedModels().Keys.First();
     }
     else
     {
         int random = new Random().Next(spawns.Length);
         player.VirtualWorld = 0;
         player.Position = new Vector3(spawns[random].X, spawns[random].Y, spawns[random].Z);
         player.Heading = spawns[random].W;
         player.GiveWeapon(Enums.Weapon.Rifle_AK47, 999);
         player.GiveWeapon(Enums.Weapon.Heavy_RocketLauncher, 999);
         player.GiveWeapon(Enums.Weapon.SMG_Uzi, 999);
     }
 }
 public void SetPlayer(ServerPlayer player)
 {
     this.Player = player;
 }
 void api_onPlayerWriteConsole(ServerPlayer player, string text)
 {
 }
 void api_onPlayerExitVehicle(ServerPlayer player, ServerVehicle vehicle)
 {
 }
 void api_onPlayerKeyDown(ServerPlayer player, int key)
 {
 }
 void api_onPlayerDisconnect(ServerPlayer player)
 {
 }
 void api_onPlayerDie(ServerPlayer player, ServerPlayer killer = null, Enums.Weapon weapon = Enums.Weapon.None)
 {
 }
 void api_onPlayerConnect(System.Net.EndPoint address, ServerPlayer player)
 {
 }
 public PlayerCamera(ServerPlayer player)
 {
     this.player = player;
 }
 public static void invokeResponse(ServerPlayer player, uint id, byte answer)
 {
     if (pool.ContainsKey(id) && pool[id].onPlayerAnswerDialog != null) pool[id].onPlayerAnswerDialog.Invoke(player, answer);
 }
 void api_onPlayerKeyUp(ServerPlayer player, int key)
 {
 }
 void api_onPlayerUpdate(ServerPlayer player)
 {
 }
Esempio n. 21
0
 public PlayerCamera(ServerPlayer player)
 {
     this.player = player;
 }
 void api_onPlayerPause(ServerPlayer player)
 {
 }
 void api_onPlayerResume(ServerPlayer player)
 {
 }
 void api_onPlayerSendCommand(ServerPlayer player, string command, string[] param)
 {
 }
Esempio n. 25
0
 public ServerRequester(ServerPlayer player)
 {
     this.player = player;
 }
 void api_onPlayerSendText(ServerPlayer player, string text)
 {
     api.writeChat(player.Nick + "(" + player.id + "): " + text);
 }
Esempio n. 27
0
        public void ExecuteJavaScript(ServerPlayer player, string script)
        {
            var bpf = new BinaryPacketFormatter(Commands.Client_JSEval, script);

            player.connection.write(bpf.getBytes());
        }
 void api_onPlayerSpawn(ServerPlayer player)
 {
 }
Esempio n. 29
0
 public void broadcastPlayerName(ServerPlayer player)
 {
     InvokeParallelForEachPlayer((single) =>
     {
         if (single != player)
         {
             var bpf = new BinaryPacketFormatter(Commands.Global_setPlayerName);
             bpf.Add(player.id);
             bpf.Add(player.Nick);
             single.connection.write(bpf.getBytes());
         }
     });
 }
 void api_onPlayerTakeDamage(ServerPlayer player, int before, int after, int delta)
 {
 }
Esempio n. 31
0
        private void onIncomingConnection(IAsyncResult iar)
        {
            Console.WriteLine("Connecting");
            TcpClient client = server.EndAcceptTcpClient(iar);

            server.BeginAcceptTcpClient(onIncomingConnection, null);

            ClientConnection connection = new ClientConnection(client);

            connection.OnConnect += delegate(string nick)
            {
                if (playerpool.Count >= config.getInt("max_players"))
                {
                    Console.WriteLine("Connection from " + nick + " rejected due to Player limit");
                    client.Close();
                    return;
                }
                Console.WriteLine("Connect from " + nick);
                uint id = findLowestFreeId();
                ServerPlayer player = new ServerPlayer(id, nick, connection);
                connection.SetPlayer(player);
                InvokeParallelForEachPlayer((p) =>
                {
                    player.connection.write(
                        new BinaryPacketFormatter(Commands.Global_createPlayer, p.id, ModelDictionary.getPedModelByName(p.Model), p.Nick)
                        .getBytes());
                    p.connection.write(
                        new BinaryPacketFormatter(Commands.Global_createPlayer, player.id, ModelDictionary.getPedModelByName("M_Y_SWAT"), nick)
                        .getBytes());
                });
                player.Nick = nick;
                player.Model = "M_Y_SWAT";
                playerpool.Add(player);
                broadcastVehiclesToPlayer(player);
                broadcastNPCsToPlayer(player);
                //broadcastPlayerName(Player);
                //broadcastPlayerModel(Player);

                api.invokeOnPlayerConnect(client.Client.RemoteEndPoint, player);
                api.invokeOnPlayerSpawn(player);

                var starter = new BinaryPacketFormatter(Commands.Client_resumeBroadcast);
                connection.write(starter.getBytes());
                connection.write(new BinaryPacketFormatter(Commands.Client_enableUDPTunnel, player.udpTunnel.getPort()).getBytes());

                connection.flush();
            };

            connection.startReceiving();
        }
 public void SetPlayer(ServerPlayer player)
 {
     this.Player = player;
 }
Esempio n. 33
0
 public void broadcastNPCsToPlayer(ServerPlayer player)
 {
     foreach (var pair in ServerNPC.NPCPool)
     {
         var bpf = new BinaryPacketFormatter(Commands.NPC_create);
         bpf.Add(pair.Value.id);
         bpf.Add(pair.Value.Position);
         bpf.Add(pair.Value.Heading);
         bpf.Add(pair.Value.Model);
         bpf.Add(pair.Value.Name);
         player.connection.write(bpf.getBytes());
     }
 }
 private void api_onPlayerSendCommand(ServerPlayer player, string command, string[] param)
 {
     if (command == "tpto")
     {
         if (param.Length != 1 || !Char.IsNumber(param[0], 0))
         {
             api.writeChat(player, "Usage: /tpto player_id");
             return;
         }
         byte id = 0;
         bool result = byte.TryParse(param[0], out id);
         if (result)
         {
             player.Position = api.getPlayer(id).Position;
         }
         return;
     }
     if (command == "help")
     {
         Console.WriteLine("abc");
         api.writeChat(player, "help");
         api.writeChat(player, "help2");
         return;
     }
     if (command == "veh")
     {
         //Vector3 carpos = MathHelper.Around(Player.Position, 4.0f);
         Vector3 carpos = player.Position + (MathHelper.HeadingToDirection(player.Heading) * 6.0f);
         api.createVehicle(param[0], carpos, MathHelper.HeadingToQuaternion(player.Heading));
         return;
     }
     if (command == "cam")
     {
         player.Camera.Reset();
         return;
     }
     if (command == "weather")
     {
         player.Weather = (ServerPlayer.WeatherType)int.Parse(param[0]);
         return;
     }
     if (command == "time")
     {
         player.GameTime = new TimeSpan(6, 30, 10);
         return;
     }
     if (command == "test")
     {
         var pos = new Vector3(2468.039f, 147.9008f, 5.838196f);
         player.requester.isObjectVisible(pos, (response) =>
         {
             api.writeChat(response.ToString());
         });
         player.requester.worldToScreenProject(pos, (response) =>
         {
             api.writeChat(response.X.ToString() + " " + response.Y.ToString());
         });
     }
 }