示例#1
0
        /// <summary>
        /// Method responsible for execute the callback of on message received handler.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="reader">The king buffer reader from received message.</param>
        private void OnMessageReceived(IClient client, IKingBufferReader reader)
        {
            try
            {
                switch (reader.ReadMessagePacket <MyPackets>())
                {
                case MyPackets.PlayerPosition:

                    float x = reader.ReadSingle();
                    float y = reader.ReadSingle();
                    float z = reader.ReadSingle();

                    Console.WriteLine($"Got position packet : {x} | {y} | {z}");

                    _networkPlayersDictionary[client].X = x;
                    _networkPlayersDictionary[client].Y = y;
                    _networkPlayersDictionary[client].Z = z;

                    _networkPlayersDictionary[client].Moved = true;
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}.");
            }
        }
示例#2
0
    public void OnMessageReceived(IKingBufferReader reader)
    {
        switch (reader.ReadMessagePacket <MyPackets>())
        {
        case MyPackets.PlayerPositionsArray:

            var lengthArr = reader.ReadInt32();

            Debug.Log($"Got positions array data num : {lengthArr}");

            for (int i = 0; i < lengthArr; i++)
            {
                var playerid = reader.ReadUInt16();

                if (!netPlayersDictionary.ContainsKey(playerid))
                {
                    netPlayersDictionary.Add(playerid, new NetPlayer());
                }

                netPlayersDictionary[playerid].X = reader.ReadSingle();
                netPlayersDictionary[playerid].Y = reader.ReadSingle();
                netPlayersDictionary[playerid].Z = reader.ReadSingle();
            }

            break;
        }
    }
示例#3
0
 /// <summary>
 /// Method responsible for execute the callback of on message received handler.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="reader">The king buffer reader from received message.</param>
 private void OnMessageReceived(IClient client, IKingBufferReader reader)
 {
     try
     {
         switch (reader.ReadMessagePacket <MyPackets>())
         {
         case MyPackets.Message:
             Console.WriteLine($"Received message: {reader.ReadString()}.");
             _server.SendMessageToAllMinus(client, KingBufferWriter.Create());
             break;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }
示例#4
0
        /// <summary>
        /// Method responsible for execute the callback of message received from client in server.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="reader">The king buffer reader from received message.</param>
        private static void OnMessageReceived(IClient client, IKingBufferReader reader)
        {
            try
            {
                if (_networkListenerType == NetworkListenerType.WSText)
                {
                    Console.WriteLine($"OnMessageReceived from {client.Id}");

                    string text = reader.ReadString();
                    Console.WriteLine($"Message: {text}");

                    var writer = KingBufferWriter.Create();

                    writer.Write("Testinho2");

                    client.SendMessage(writer);
                }
                else
                {
                    switch (reader.ReadMessagePacket <MyPackets>())
                    {
                    case MyPackets.PacketOne:
                        Console.WriteLine($"OnMessageReceived PacketOne from {client.Id}");
                        Console.WriteLine($"Message: {reader.ReadString()}");

                        var writer = KingBufferWriter.Create();

                        writer.Write(MyPackets.PacketOne);
                        writer.Write("Testinho2");

                        client.SendMessage(writer);

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}.");
            }
        }
示例#5
0
 /// <summary>
 /// Method responsible for execute the callback of message received from server in client.
 /// </summary>
 /// <param name="reader">The king buffer reader from received message.</param>
 private static void OnMessageReceived(IKingBufferReader reader)
 {
     try
     {
         if (_networkListenerType == NetworkListenerType.WSText)
         {
             Console.WriteLine($"OnMessageReceived: {reader.ReadString()}");
         }
         else
         {
             switch (reader.ReadMessagePacket <MyPackets>())
             {
             case MyPackets.PacketOne:
                 Console.WriteLine("OnMessageReceived for PacketOne");
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }