Пример #1
0
        // Takes an update and the sender and then distributes the update to subscribers
        public void HandleUpdate(List <byte> data, string senderID)
        {
            Debug.Log("Update recieved from " + senderID);

            // Strip the header off the update
            HeaderManager.Header header = HeaderManager.StripHeader(data);

            if (header.protocol == PROTOCOL_VERSION)
            {
                // If/else tree for handling the message type
                if (header.messageType == PLAYER)
                {
                    Debug.Log("Notifying everyone on the player channel");

                    // Notify player subscribers of player updates
                    NotifyAll(data, Channel.PLAYER);
                }
                else if (header.messageType == OBSTACLE)
                {
                    Debug.Log("Notifying everyone on the obstacle channel");

                    // Notify all obstacle subscribers of an obstacle update
                    NotifyAll(data, Channel.OBSTACLE);
                }
                else if (header.messageType == PUSHBLOCK)
                {
                    Debug.Log("Notifying everyone on the pushblock channel");

                    // Notify all obstacle subscribers of an obstacle update
                    NotifyAll(data, Channel.PUSHBLOCK);
                }
                else if (header.messageType == CHAT && chatController != null)
                {
                    Debug.Log("Notifying ChatController");

                    // Give chat controller the message
                    chatController.ReceiveMessage(data);
                }
                else if (header.messageType == CLOCK && clock != null)
                {
                    Debug.Log("Notifying Clock");

                    ApplyClockUpdate(data);
                }
                else if (header.messageType == LEADERBOARDS)
                {
                    FinalizeLevel.position    = data [0];
                    FinalizeLevel.positionSet = true;
                }
                else if (header.messageType == GAMER_TAG)
                {
                    MultiPlayerController.Instance.theirName = Encoding.ASCII.GetString(data.ToArray());
                }
                else
                {
                    throw new MessageHeaderException("invalid update identifier");
                }
            }
            else
            {
                throw new MessageHeaderException("invalid protocol version");
            }
        }
Пример #2
0
 private void ApplyHeader(List <byte> data, byte type)
 {
     HeaderManager.ApplyHeader(data, new HeaderManager.Header(PROTOCOL_VERSION, type));
 }