public bool ShouldQueue(BaseWorldMessage message)
 {
     if (!worldManager.PlayerInitialized) {
         // The connection isn't yet set up -- we only handle the login response message here
         if (message is AuthorizedLoginResponseMessage) {
             AuthorizedLoginResponseMessage response = (AuthorizedLoginResponseMessage)message;
             // I need to handle the response in this thread, because I don't want to skip any messages
             // while I'm waiting for the login response to be handled by another thread.
             if (response.Success) {
                 worldManager.PlayerId = response.Oid;
                 log.InfoFormat("Player initialized -- playerId = " + worldManager.PlayerId);
             } else {
                 log.Error("Failure with AuthorizedLoginResponse message");
             }
             // Still queue the login response for handling by other code, so the login message can be
             // dealt with if needed.
         } else {
             log.WarnFormat("Ignoring message {0}, since player is not set up", message);
             return false;
         }
     }
     return true;
 }
 public virtual void QueueMessage(BaseWorldMessage message)
 {
     Monitor.Enter(messageQueue);
     try {
         messageQueue.Enqueue(message);
         messagesQueued++;
     } finally {
         Monitor.Exit(messageQueue);
     }
 }
        private bool HandleMessage(BaseWorldMessage message)
        {
            if (queueFilter != null && !queueFilter(message))
                // Skip this message, and pull it from the queue
                return true;
            List<WorldMessageHandler> handlers;
            // Run through the pre-handlers for the message -- these can delay processing
            if (preMessageHandlers.TryGetValue(message.MessageType, out handlers)) {
                foreach (WorldMessageHandler handler in handlers) {
                    handler(message);
                    if (message.DelayHandling) {
                        //Logger.Log(0, "Message {0} has DelayHandling set", message.MessageType);
                        return false;
                    }
                }
            }

            log.InfoFormat("Handle message called for {0}", message);
            if (messageHandlers.TryGetValue(message.MessageType, out handlers)) {
                foreach (WorldMessageHandler handler in handlers) {
                    long before = System.Environment.TickCount;
                    log.DebugFormat("Handling message: {0}", message.MessageType);
                    try {
                        handler(message);
                        if (message.AbortHandling) {
                            //Logger.Log(0, "Message {0} has DelayHandling set", message.MessageType);
                            return false;
                        }
                    } catch (Exception e) {
                        log.WarnFormat("Failed to handle message {0}: {1}", message.MessageType, e);
                    }
                    log.DebugFormat("Handled message: {0} with oid {1}; took {2}ms", message.MessageType, message.Oid, System.Environment.TickCount - before);
                }
            } else {
                log.WarnFormat("No handler for message type: {0}", message.MessageType);
            }
            log.DebugFormat("Handle message completed for {0}", message);

            if (postMessageHandlers.TryGetValue(message.MessageType, out handlers)) {
                foreach (WorldMessageHandler handler in handlers) {
                    handler(message);
                }
            }

            messagesHandled++;
            return true;
        }
 public override void QueueMessage(BaseWorldMessage message)
 {
     Monitor.Enter(messageQueue);
     try {
         bool addToQueue = true;
         if (message.MessageType == WorldMessageType.FragmentMessage) {
             HandleFragmentMessage(message);
             FragmentMessage fragMessage = (FragmentMessage)message;
             if (fragMessage.FragmentNumber != 0)
                 addToQueue = false;
         }
         if (addToQueue)
             messageQueue.Add(message);
         AssembleFragments();
         while (messageQueue.Count > 0) {
             BaseWorldMessage message2 = messageQueue[0];
             // we can now handle messages until we get a fragment
             if (message2.MessageType == WorldMessageType.FragmentMessage)
                 break;
             if (message2.MessageType == WorldMessageType.AggregatedRDP) {
                 AggregatedRDPMessage aggregateMessage = (AggregatedRDPMessage)message2;
                 foreach (BaseWorldMessage message3 in aggregateMessage.SubMessages) {
                     MessageDispatcher.Instance.QueueMessage(message3);
                 }
             } else {
                 MessageDispatcher.Instance.QueueMessage(message2);
             }
             messageQueue.RemoveAt(0);
         }
     } finally {
         Monitor.Exit(messageQueue);
     }
 }
 /// <summary>
 ///   Handle fragmented messages
 /// </summary>
 /// <param name="message"></param>
 private void HandleFragmentMessage(BaseWorldMessage message)
 {
     FragmentMessage fragment = (FragmentMessage)message;
     log.InfoFormat("Got message fragment for {0}: {1}/{2}",
                    fragment.MessageNumber, fragment.FragmentNumber, fragment.NumFragments);
     if (!fragmentDictionary.ContainsKey(fragment.MessageNumber))
         fragmentDictionary[fragment.MessageNumber] = new FragmentInfo();
     FragmentInfo fragInfo = fragmentDictionary[fragment.MessageNumber];
     fragInfo.payloads[fragment.FragmentNumber] = fragment.Payload;
     if (fragment.FragmentNumber == 0)
         fragInfo.numFragments = fragment.NumFragments;
 }
예제 #6
0
        private void HandlePortal(BaseWorldMessage message)
        {
            PortalMessage portalMessage = (PortalMessage)message;
            Write("Transporting via portal to alternate world.");

            loginSettings.worldId = portalMessage.WorldId;
            loginSettings.characterId = portalMessage.CharacterId;
            portalMessage.AbortHandling = true;

            needConnect = true;
        }
예제 #7
0
 private void HandleUiTheme(BaseWorldMessage message)
 {
     UiThemeMessage uiTheme = (UiThemeMessage)message;
     uiModules = new List<string>(uiTheme.UiModules);
     if (uiModules.Count == 0)
         uiModules.Add("basic.toc");
     keyBindingsFile = uiTheme.KeyBindingsFile;
     ReloadUiElements();
 }
예제 #8
0
 private void HandleLoginResponse(BaseWorldMessage message)
 {
     LoginResponseMessage loginResponse = (LoginResponseMessage)message;
     loginFailed = !loginResponse.Success;
     loginMessage = loginResponse.Message;
 }
예제 #9
0
 private void HandleAuthorizedLoginResponse(BaseWorldMessage message)
 {
     AuthorizedLoginResponseMessage loginResponse = (AuthorizedLoginResponseMessage)message;
     loginFailed = !loginResponse.Success;
     loginMessage = loginResponse.Message;
     worldServerVersion = loginResponse.Version;
     // If the server version starts with "2007-07-20" or with
     // "1.0", it's a pre-1.1 version, so don't expect
     // LoadingStateMessages.
     log.InfoFormat("In HandleAuthorizedLoginResponse, testing server version '{0}'", worldServerVersion);
     if ((worldServerVersion.Length >= 10 && worldServerVersion.Substring(0, 10) == "2007-07-20") ||
         (worldServerVersion.Length >= 3 && worldServerVersion.Substring(0, 3) == "1.0"))
         fullyInitialized = true;
     if (worldServerVersion.Length >= 3 && worldServerVersion.Substring(0, 3) == "1.5")
         serverRelease1_5 = true;
     log.InfoFormat("World Server Version: {0}", worldServerVersion);
 }
예제 #10
0
 public void HandleObjectProperty(BaseWorldMessage message)
 {
     ObjectPropertyMessage propMessage = (ObjectPropertyMessage)message;
     // Debugging
     foreach (string key in propMessage.Properties.Keys) {
         object val = propMessage.Properties[key];
         log.DebugFormat("HandleObjectProperty for OID {0}, setting prop {1} = {2}",
                        message.Oid, key, val);
     }
     HandleObjectPropertyHelper(message.Oid, propMessage.Properties);
 }
예제 #11
0
 /// <summary>
 ///   Special handling for DirectionMessage objects.
 ///   This updates the collision volumes if needed.
 /// </summary>
 /// <param name="message">the message object from the server</param>
 public void HandleDirection(BaseWorldMessage message)
 {
     DirectionMessage dirMessage = message as DirectionMessage;
     ObjectNode objNode = worldManager.GetObjectNode(dirMessage.Oid);
     if (objNode != null) {
         bool static_object = true;
         if ((objNode.ObjectType == ObjectNodeType.Npc) ||
             (objNode.ObjectType == ObjectNodeType.User))
         {
             static_object = false;
         }
         if (static_object) {
             RemoveCollisionObject(objNode);
             AddCollisionObject(objNode);
         } else {
             if (objNode.Collider != null)
                 objNode.Collider.Transform(objNode.SceneNode.DerivedScale,
                                            objNode.SceneNode.DerivedOrientation,
                                            objNode.SceneNode.DerivedPosition);
         }
     }
 }
예제 #12
0
		private void HandleUiTheme(BaseWorldMessage message) {
			UiThemeMessage uiTheme = (UiThemeMessage)message;
			uiModules = new List<string>(uiTheme.UiModules);
			if (uiModules.Count == 0)
				uiModules.Add("basic.toc");
		}