home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / client / message.cs < prev    next >
Encoding:
Text File  |  2006-09-25  |  2.9 KB  |  80 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6.  
  7. //-----------------------------------------------------------------------------
  8. // Functions that process commands sent from the server.
  9.  
  10.  
  11. // This function is for chat messages only; it is invoked on the client when
  12. // the server does a commandToClient with the tag ChatMessage.  (Cf. the
  13. // functions chatMessage* in common/server/message.cs.)
  14.  
  15. // This just invokes onChatMessage, which the mod code must define.
  16.  
  17. function clientCmdChatMessage(%sender, %voice, %pitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  18. {
  19.    onChatMessage(detag(%msgString), %voice, %pitch);
  20. }
  21.  
  22.  
  23. // Game event descriptions, which may or may not include text messages, can be
  24. // sent using the message* functions in common/server/message.cs.  Those
  25. // functions do commandToClient with the tag ServerMessage, which invokes the
  26. // function below.
  27.  
  28. // For ServerMessage messages, the client can install callbacks that will be
  29. // run, according to the "type" of the message.
  30.  
  31. function clientCmdServerMessage(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  32. {
  33.    // Get the message type; terminates at any whitespace.
  34.    %tag = getWord(%msgType, 0);
  35.  
  36.    // First see if there is a callback installed that doesn't have a type;
  37.    // if so, that callback is always executed when a message arrives.
  38.    for (%i = 0; (%func = $MSGCB["", %i]) !$= ""; %i++) {
  39.       call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
  40.    }
  41.  
  42.    // Next look for a callback for this particular type of ServerMessage.
  43.    if (%tag !$= "") {
  44.       for (%i = 0; (%func = $MSGCB[%tag, %i]) !$= ""; %i++) {
  45.          call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
  46.       }
  47.    }
  48. }
  49.  
  50. // Called by the client to install a callback for a particular type of
  51. // ServerMessage.
  52. function addMessageCallback(%msgType, %func)
  53. {
  54.    for (%i = 0; (%afunc = $MSGCB[%msgType, %i]) !$= ""; %i++) {
  55.       // If it already exists as a callback for this type,
  56.       // nothing to do.
  57.       if (%afunc $= %func) {
  58.          return;
  59.       }
  60.    }
  61.    // Set it up.
  62.    $MSGCB[%msgType, %i] = %func;
  63. }
  64.  
  65.  
  66.  
  67. // The following is the callback that will be executed for every ServerMessage,
  68. // because we're going to install it without a specified type.  Any type-
  69. // specific callbacks will be executed afterward.
  70.  
  71. // This just invokes onServerMessage, which the mod code must define.
  72.  
  73. function defaultMessageCallback(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  74. {
  75.    onServerMessage(detag(%msgString));
  76. }
  77.  
  78. // Register that default message handler now.
  79. addMessageCallback("", defaultMessageCallback);
  80.