public ServerPlayer(uint id, string nick, ClientConnection connection)
 {
     this.id = id;
     this.nick = nick;
     virtualWorld = 0;
     model = "F_Y_NURSE";
     this.connection = connection;
     requester = new ServerRequester(this);
     data = UpdateDataStruct.Zero;
     isDead = true;
     Camera = new PlayerCamera(this);
     udpTunnel = new ServerUDPTunnel(this);
 }
示例#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();
        }
 public Request(ClientConnection connection, Commands action, Action<object[]> onComplete)
 {
     InitInstance(connection, action, onComplete);
 }
 private void InitInstance(ClientConnection connection, Commands action, Action<object[]> onComplete)
 {
     if (requestPool == null) requestPool = new Dictionary<uint, Request>();
     this.action = action;
     this.connection = connection;
     this.onComplete = onComplete;
     uint id = findLowestFreeId();
     requestPool.Add(id, this);
     bpf = new BinaryPacketFormatter(action);
     bpf.Add(id);
 }