Esempio n. 1
0
        private void DecodeMessage(NetworkMessageType messageType, byte[] bytes, int length)
        {
            var incomingData = new byte[length];

            Array.Copy(bytes, 1, incomingData, 0, length - 1);
            string clientMessage = Encoding.ASCII.GetString(incomingData);


            var strings = clientMessage.Split(':');
            var token   = strings[0];

            Console.WriteLine(messageType.ToString() + " -- " + clientMessage);
        }
Esempio n. 2
0
        private void DecodeMessage(NetworkMessageType messageType, int payloadLength, byte[] bytes)
        {
            try
            {
                string jsonPayload = "";
                if (payloadLength > 0)
                {
                    var payload = new byte[payloadLength];
                    Array.Copy(bytes, 2, payload, 0, payloadLength);
                    jsonPayload = Encoding.ASCII.GetString(payload);
                }

                if (messageType == NetworkMessageType.test)
                {
                    Console.WriteLine("TEST ACK RECEIVED");
                }

                if (messageType == NetworkMessageType.objectUpdate)
                {
                    GameObjectState objectState = JsonConvert.DeserializeObject <GameObjectState>(jsonPayload);
                    //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading);

                    if (objectState.Name == tankName)
                    {
                        ourMostRecentState = objectState;
                    }
                }

                else
                {
                    Console.WriteLine(messageType.ToString());
                    Console.WriteLine(jsonPayload);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Message decode exception " + e);
            }
        }
Esempio n. 3
0
        private void DecodeMessage(NetworkMessageType messageType, int payloadLength, byte[] bytes)
        {
            string jsonPayload = "";

            try
            {
                if (payloadLength > 0)
                {
                    var payload = new byte[payloadLength];
                    Array.Copy(bytes, 2, payload, 0, payloadLength);
                    jsonPayload = Encoding.ASCII.GetString(payload);
                }

                if (messageType == NetworkMessageType.test)
                {
                    //Console.WriteLine("TEST ACK RECEIVED");
                }

                if (messageType == NetworkMessageType.objectUpdate)
                {
                    messageCount++;
                    GameObjectState objectState = JsonConvert.DeserializeObject <GameObjectState>(jsonPayload);
                    //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading);

                    if (objectState.Name == tankName)
                    {
                        ourMostRecentState = objectState;
                        //Console.WriteLine("ID: " + objectState.Id + " Type: " + objectState.Type + " Name: " + objectState.Name + " ---- " + objectState.X + "," + objectState.Y + " : " + objectState.Heading + " : " + objectState.TurretHeading);
                    }
                    else
                    {
                        if (seenObjects.ContainsKey(objectState.Id))
                        {
                            seenObjects[objectState.Id]       = objectState;
                            lastStateReceived[objectState.Id] = DateTime.Now;
                        }
                        else
                        {
                            seenObjects.Add(objectState.Id, objectState);

                            if (!lastStateReceived.ContainsKey(objectState.Id))
                            {
                                lastStateReceived.Add(objectState.Id, DateTime.Now);
                            }
                            else
                            {
                                lastStateReceived[objectState.Id] = DateTime.Now;
                            }
                        }
                    }
                }

                if (messageType == NetworkMessageType.kill)
                {
                    unbankedPoints++;
                    Console.WriteLine("KILL CONFIRMED");
                }
                if (messageType == NetworkMessageType.snitchPickup)
                {
                    snitchCarrier = JsonConvert.DeserializeObject <Tank>(jsonPayload);
                    Console.WriteLine("SNITCH CARRIER DETECTED");
                }
                if (messageType == NetworkMessageType.enteredGoal)
                {
                    botStateMachine.TransitionTo(TurretBehaviour.findTarget);
                    botStateMachine.TransitionTo(MoveBehaviour.moveToRandomPoint);
                    unbankedPoints = 0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Message decode exception " + e);
                Console.WriteLine("Messaage Type: " + messageType.ToString());
                Console.WriteLine("Payload Length: " + payloadLength);
                Console.WriteLine("Message Length: " + bytes.Length);
                Console.WriteLine(jsonPayload);
            }
        }