Ejemplo n.º 1
0
        private void updatePing()
        {
            var bpf = new BinaryPacketFormatter(Commands.Client_ping);

            bpf.Add(DateTime.Now.Ticks);
            connection.write(bpf.getBytes());
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
 public void Flush()
 {
     connection.write(bpf.getBytes());
 }