Exemple #1
0
        public void HandlePacket(NetTcpServer server, NetTcpClient client, object packet)
        {
            switch (packet)
            {
            case PlayerShotPacket playerShotPacket:
                PacketHandlers.ProcessPacket(CreatePacketContext(playerShotPacket, client));
                break;

            case PlayerSpawnAtPacket playerSpawnAtPacket:
                PacketHandlers.ProcessPacket(CreatePacketContext(playerSpawnAtPacket, client));
                break;

            case PlayerTeamJoinPacket playerTeamJoinPacket:
                PacketHandlers.ProcessPacket(CreatePacketContext(playerTeamJoinPacket, client));
                break;

            case PlayerJumpPacket playerJumpPacket:
                PacketHandlers.ProcessPacket(CreatePacketContext(playerJumpPacket, client));
                break;

            case PlayerFlowPacket playerFlowPacket:
                PacketHandlers.ProcessPacket(CreatePacketContext(playerFlowPacket, client));
                break;
            }
        }
Exemple #2
0
        public BeepClient()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("clientSettings.json", false, true)
                                    .Build();

            using var loggerFactory = LoggerFactory.Create(x => x
                                                           .AddConfiguration(config.GetSection("Logging"))
                                                           .AddConsole());

            Logger = loggerFactory.CreateLogger <BeepClient>();

            IConfigurationSection networkConfig = config.GetSection("Network");

            IPAddress hostAddress = IPAddress.Parse(networkConfig.GetValue <string>("Address"));
            int       port        = networkConfig.GetValue <int>("TcpPort");

            //TcpClient tcpClient = new TcpClient(new IPEndPoint(hostAddress, port));
            TcpClient tcpClient = new TcpClient(networkConfig.GetValue <string>("Address"), port);

            NetTcpClient client = new NetTcpClient(tcpClient, new StreamProtobuf(PrefixStyle.Base128, Packet.PacketTypes));

            client.PacketReceivedEvent += HandlePacket;

            BeepLiveSfml = new BeepLiveSfml(new MessageSender(client));

            _ = client.AcceptPackets();

            BeepLiveSfml.Run();
        }
 public PacketContext(TPacket packet, BeepServer server, NetTcpClient sender, ILogger logger)
 {
     Packet = packet;
     Server = server;
     Sender = sender;
     Logger = logger;
 }
Exemple #4
0
 /// <summary>
 /// On Send data
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="data"></param>
 void tcpClient_onSendData(NetTcpClient sender, Common.Model.CommandResult data)
 {
     if (null != onSendData)
     {
         onSendData(sender, data);
     }
 }
Exemple #5
0
 private void Client_onReceiveData(NetTcpClient sender, CommandResult data)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, "C - Receive data" + data.message);
     });
 }
Exemple #6
0
 private void Server_onAcceptClient(NetTcpServer sender, NetTcpClient client)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, "Connected");
     });
 }
Exemple #7
0
 void tcpClient_onError(NetTcpClient sender, Common.Model.CommandResult data)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, sender.host + "- > Error : " + data.message);
     });
 }
Exemple #8
0
 void tcpClient_onConnect(NetTcpClient sender)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, sender.host + "- > Connect");
     });
 }
Exemple #9
0
 void tcpClient_onReceiveData(NetTcpClient sender, Common.Model.CommandResult data)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, sender.host + "- > Recieve data " + Encoding.UTF8.GetString(data.model as byte[]));
     });
 }
Exemple #10
0
        /// <summary>
        /// OnError
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        void tcpClient_onError(NetTcpClient sender, Common.Model.CommandResult data)
        {
            if (null != onError)
            {
                onError(sender, data);

                connectCount++;
                if (null != writeThread)
                {
                    writeThread.Abort();
                }
            }

            ///TODO : PARSE ERROR
            if (data.id == 999)
            {
                if (connectCount < 4)
                {
                    tryToConnect();
                    if (msr.WaitOne())
                    {
                        connect();
                    }
                }
            }
        }
Exemple #11
0
 /// <summary>
 /// On Connect
 /// </summary>
 /// <param name="sender"></param>
 void tcpClient_onConnect(NetTcpClient sender)
 {
     if (null != onConnect)
     {
         onConnect(sender);
     }
 }
Exemple #12
0
 private void Server_onReceiveData(NetTcpServer sender, NetTcpClient client, CommandResult data)
 {
     Invoke((Action) delegate
     {
         listBox1.Items.Insert(0, "S - Receive data" + data.message);
     });
     client.write("Response ");
 }
Exemple #13
0
 /// <summary>
 /// OnDisConnect
 /// </summary>
 /// <param name="sender"></param>
 void tcpClient_onDisconnect(NetTcpClient sender)
 {
     if (null != onDisconnect)
     {
         writeThread.Abort();
         onDisconnect(sender);
     }
 }
Exemple #14
0
 /// <summary>
 /// On Connect
 /// </summary>
 /// <param name="sender"></param>
 void tcpClient_onConnect(NetTcpClient sender)
 {
     if (null != onConnect)
     {
         onConnect(sender);
     }
     tryToWriteData();
     connectCount = 0;
 }
Exemple #15
0
        void t_onReceiveData(NetTcpClient sender, Common.Model.CommandResult data)
        {
            string s = Encoding.UTF8.GetString(data.model as byte[]);

            Invoke((Action) delegate
            {
                listBox1.Items.Insert(0, s);
            });
        }
Exemple #16
0
        /*
         *      Commands (CLIENT):
         *                      GET_LAST_TAG
         *
         *      Commands (SERVER):
         *                      NEW_TAG
         */

        #region Methods
        /// <summary>
        /// Parse Command
        /// </summary>
        /// <param name="client"></param>
        /// <param name="data"></param>
        public static void parseCmd(NetTcpClient client, CommandResult data)
        {
            if ((null != client) && (null != data) && !data.message.isNullOrEmptyOrWhiteSpaceOrLen())
            {
                string cmd = data.message.ToLower();

                if (cmd == "get_last_tag")
                {
                    // Get last tag
                }
            }
        }
Exemple #17
0
        private void button4_Click(object sender, EventArgs e)
        {
            server = new NetTcpServer(10000, 1024);
            client = new NetTcpClient("127.0.0.1", 10000, 1024);

            server.start();
            client.connect();

            client.onReceiveData  += Client_onReceiveData;
            server.onReceiveData  += Server_onReceiveData;
            server.onAcceptClient += Server_onAcceptClient;
        }
Exemple #18
0
        public AntennaClient(string host, int port, int bufferSize)
        {
            msr = new ManualResetEvent(false);
            connectorInterval = new TimeSpan(0, 0, 15);
            tcpClient         = new NetTcpClient(host, port, bufferSize);

            tcpClient.onConnect     += tcpClient_onConnect;
            tcpClient.onDisconnect  += tcpClient_onDisconnect;
            tcpClient.onError       += tcpClient_onError;
            tcpClient.onReceiveData += tcpClient_onReceiveData;
            tcpClient.onSendData    += tcpClient_onSendData;
        }
Exemple #19
0
 public void HandlePacket(NetTcpClient client, object packet)
 {
     switch (packet)
     {
     case PlayerJumpPacket _:
     case PlayerShotPacket _:
     case PlayerSpawnAtPacket _:
     case PlayerTeamJoinPacket _:
     case ServerFlowPacket _:
     case SyncPacket _:
         BeepLiveSfml.HandlePacket((Packet)packet);
         break;
     }
 }
Exemple #20
0
        /// <summary>
        /// OnError
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        void tcpClient_onError(NetTcpClient sender, CommandResult data)
        {
            if (null != onError)
            {
                onError(sender, data);
                connectCount++;
            }

            ///TODO : PARSE ERROR
            if (data.id == 999)
            {
                if (connectCount < 10)
                {
                    tryToConnect();
                    if (msr.WaitOne())
                    {
                        connect();
                    }
                }
            }
        }
Exemple #21
0
 private PacketContext <TPacket> CreatePacketContext <TPacket>(TPacket packet, NetTcpClient sender) where TPacket : Packet =>
 new PacketContext <TPacket>(packet, this, sender, Logger);
Exemple #22
0
 public MessageSender(NetTcpClient client)
 {
     _client = client;
 }
Exemple #23
0
 /// <summary>
 /// TcpServer
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="client"></param>
 /// <param name="data"></param>
 private void TcpServer_onReceiveData(NetTcpServer sender, NetTcpClient client, CommandResult data)
 {
     Helper.ClientMethodParser.parseCmd(client, data);
 }