Torque3D Documentation / _generateds / netExamples.cpp

netExamples.cpp

Engine/source/app/net/netExamples.cpp

More...

Classes:

Public Functions

ConsoleDocClass(SimpleMessageEvent , "@brief A very simple example of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">event.\n\n</a>" "This object exists purely <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> instructional purposes. It is primarily " "geared toward developers that wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> understand the inner-working of " "Torque 3D's networking system. This is not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development.\n\n</a> " "@see <a href="/coding/class/classnetevent/">NetEvent</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the inner workings of network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">events\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )
ConsoleDocClass(SimpleNetObject , "@brief A very simple example of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> class derived from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetObject.\n\n</a>" "This object exists purely <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> instructional purposes. It is primarily " "geared toward developers that wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> understand the inner-working of " "Torque 3D's networking system. This is not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development.\n\n</a> " "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// On the server)
DefineEngineMethod(SimpleNetObject , setMessage , void , (const char *msg) , "@brief Sets the internal message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable.\n\n</a>" "<a href="/coding/class/classsimplenetobject/">SimpleNetObject</a> is set up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> automatically transmit this <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "all connected clients. It will appear in the clients' <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param msg The <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">send\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// On the server, create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> SimpleNetObject. This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> ghost <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">always\n</a>" "//object so it will be immediately ghosted <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> all connected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clients.\n</a>" " $s, change the message. This will cause it <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "//be sent <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> all connected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clients.\n</a>" " $s.setMessage(\"A <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message from me!\");\n\n" "// All connected clients will now see in their <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console:\n</a>" "// \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// Go message: A <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">me!\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )
DefineEngineStaticMethod(SimpleMessageEvent , msg , void , (NetConnection *con, const char *message) , "@brief Send <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classsimplemessageevent/">SimpleMessageEvent</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "The far end that receives the message will print the message out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param con The unique ID of the connection <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> transmit <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param message The string containing the message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">transmit\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Send <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the other end of the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetConnection\n</a>" "SimpleMessageEvent::msg( %conn, \"A message from me!\");\n\n" "// The far end will see the following in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console\n</a>" "// (Note: The number may be something other than 1796 as it is the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SimObjectID\n</a>" "// of the received event)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// RMSG 1796 A message from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">me!\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(SimpleMessageEvent , "@brief A very simple example of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">event.\n\n</a>" "This object exists purely <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> instructional purposes. It is primarily " "geared toward developers that wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> understand the inner-working of " "Torque 3D's networking system. This is not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development.\n\n</a> " "@see <a href="/coding/class/classnetevent/">NetEvent</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the inner workings of network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">events\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Networking\n</a>" )

ConsoleDocClass(SimpleNetObject , "@brief A very simple example of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> class derived from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetObject.\n\n</a>" "This object exists purely <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> instructional purposes. It is primarily " "geared toward developers that wish <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> understand the inner-working of " "Torque 3D's networking system. This is not intended <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> actual game " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">development.\n\n</a> " "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// On the server)

DefineEngineMethod(SimpleNetObject , setMessage , void , (const char *msg) , "@brief Sets the internal message <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable.\n\n</a>" "<a href="/coding/class/classsimplenetobject/">SimpleNetObject</a> is set up <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> automatically transmit this <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "all connected clients. It will appear in the clients' <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param msg The <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">send\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// On the server, create <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> SimpleNetObject. This is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> ghost <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">always\n</a>" "//object so it will be immediately ghosted <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> all connected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clients.\n</a>" " $s, change the message. This will cause it <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "//be sent <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> all connected <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clients.\n</a>" " $s.setMessage(\"A <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message from me!\");\n\n" "// All connected clients will now see in their <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console:\n</a>" "// \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// Go message: A <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> message from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">me!\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )

DefineEngineStaticMethod(SimpleMessageEvent , msg , void , (NetConnection *con, const char *message) , "@brief Send <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classsimplemessageevent/">SimpleMessageEvent</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">connection.\n\n</a>" "The far end that receives the message will print the message out <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param con The unique ID of the connection <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> transmit <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">to\n</a>" "@param message The string containing the message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">transmit\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Send <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> message <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the other end of the given <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">NetConnection\n</a>" "SimpleMessageEvent::msg( %conn, \"A message from me!\");\n\n" "// The far end will see the following in the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console\n</a>" "// (Note: The number may be something other than 1796 as it is the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SimObjectID\n</a>" "// of the received event)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "// RMSG 1796 A message from <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">me!\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" )

IMPLEMENT_CO_NETEVENT_V1(SimpleMessageEvent )

IMPLEMENT_CO_NETOBJECT_V1(SimpleNetObject )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "console/simBase.h"
 26#include "sim/netConnection.h"
 27#include "core/stream/bitStream.h"
 28#include "sim/netObject.h"
 29#include "console/engineAPI.h"
 30
 31class SimpleMessageEvent : public NetEvent
 32{
 33   char *msg;
 34public:
 35   typedef NetEvent Parent;
 36   SimpleMessageEvent(const char *message = NULL)
 37      {
 38         if(message)
 39            msg = dStrdup(message);
 40         else
 41            msg = NULL;
 42      }
 43   ~SimpleMessageEvent()
 44      { dFree(msg); }
 45
 46   virtual void pack(NetConnection* /*ps*/, BitStream *bstream)
 47      { bstream->writeString(msg); }
 48   virtual void write(NetConnection*, BitStream *bstream)
 49      { bstream->writeString(msg); }
 50   virtual void unpack(NetConnection* /*ps*/, BitStream *bstream)
 51      { char buf[256]; bstream->readString(buf); msg = dStrdup(buf); }
 52   virtual void process(NetConnection *)
 53      { Con::printf("RMSG %d  %s", mSourceId, msg); }
 54
 55   DECLARE_CONOBJECT(SimpleMessageEvent);
 56};
 57
 58IMPLEMENT_CO_NETEVENT_V1(SimpleMessageEvent);
 59
 60ConsoleDocClass( SimpleMessageEvent,
 61   "@brief A very simple example of a network event.\n\n"
 62
 63   "This object exists purely for instructional purposes. It is primarily "
 64   "geared toward developers that wish to understand the inner-working of "
 65   "Torque 3D's networking system. This is not intended for actual game "
 66   "development.\n\n "
 67
 68   "@see NetEvent for the inner workings of network events\n\n"
 69
 70   "@ingroup Networking\n");
 71
 72DefineEngineStaticMethod( SimpleMessageEvent, msg, void, (NetConnection* con, const char* message),,
 73   "@brief Send a SimpleMessageEvent message to the specified connection.\n\n"
 74
 75   "The far end that receives the message will print the message out to the console.\n"
 76
 77   "@param con The unique ID of the connection to transmit to\n"
 78   "@param message The string containing the message to transmit\n\n"
 79   
 80   "@tsexample\n"
 81      "// Send a message to the other end of the given NetConnection\n"
 82      "SimpleMessageEvent::msg( %conn, \"A message from me!\");\n\n"
 83
 84      "// The far end will see the following in the console\n"
 85      "// (Note: The number may be something other than 1796 as it is the SimObjectID\n"
 86      "// of the received event)\n"
 87      "// \n"
 88      "// RMSG 1796  A message from me!\n"
 89   "@endtsexample\n\n"
 90   )
 91{
 92   //NetConnection *con = (NetConnection *) Sim::findObject(argv[1]);
 93
 94   if(con)
 95      con->postNetEvent(new SimpleMessageEvent(message));
 96}
 97
 98//ConsoleFunction( msg, void, 3, 3, "(NetConnection id, string message)"
 99//                "Send a SimpleNetObject message to the specified connection.")
100//{
101//   NetConnection *con = (NetConnection *) Sim::findObject(argv[1]);
102//   if(con)
103//      con->postNetEvent(new SimpleMessageEvent(argv[2]));
104//}
105
106class SimpleNetObject : public NetObject
107{
108   typedef NetObject Parent;
109public:
110   char message[256];
111   SimpleNetObject()
112   {
113      mNetFlags.set(ScopeAlways | Ghostable);
114      dStrcpy(message, "Hello World!", 256);
115   }
116   U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
117   {
118      stream->writeString(message);
119      return 0;
120   }
121   void unpackUpdate(NetConnection *conn, BitStream *stream)
122   {
123      stream->readString(message);
124      Con::printf("Got message: %s", message);
125   }
126   void setMessage(const char *msg)
127   {
128      setMaskBits(1);
129      dStrcpy(message, msg, 256);
130   }
131
132   DECLARE_CONOBJECT(SimpleNetObject);
133};
134
135IMPLEMENT_CO_NETOBJECT_V1(SimpleNetObject);
136
137ConsoleDocClass( SimpleNetObject,
138   "@brief A very simple example of a class derived from NetObject.\n\n"
139
140   "This object exists purely for instructional purposes. It is primarily "
141   "geared toward developers that wish to understand the inner-working of "
142   "Torque 3D's networking system. This is not intended for actual game "
143   "development.\n\n "
144   
145   "@tsexample\n"
146      "// On the server, create a new SimpleNetObject.  This is a ghost always\n"
147      "// object so it will be immediately ghosted to all connected clients.\n"
148      "$s = new SimpleNetObject();\n\n"
149
150      "// All connected clients will see the following in their console:\n"
151      "// \n"
152      "// Got message: Hello World!\n"
153   "@endtsexample\n\n"
154
155   "@see NetObject for a full breakdown of this example object\n"
156
157   "@ingroup Networking\n");
158
159DefineEngineMethod( SimpleNetObject, setMessage, void, (const char* msg),,
160   "@brief Sets the internal message variable.\n\n"
161
162   "SimpleNetObject is set up to automatically transmit this new message to "
163   "all connected clients.  It will appear in the clients' console.\n"
164
165   "@param msg The new message to send\n\n"
166   
167   "@tsexample\n"
168      "// On the server, create a new SimpleNetObject.  This is a ghost always\n"
169      "// object so it will be immediately ghosted to all connected clients.\n"
170      "$s = new SimpleNetObject();\n\n"
171
172      "// All connected clients will see the following in their console:\n"
173      "// \n"
174      "// Got message: Hello World!\n\n"
175
176      "// Now again on the server, change the message.  This will cause it to\n"
177      "// be sent to all connected clients.\n"
178      "$s.setMessage(\"A new message from me!\");\n\n"
179
180      "// All connected clients will now see in their console:\n"
181      "// \n"
182      "// Go message: A new message from me!\n"
183   "@endtsexample\n\n"
184   )
185{
186   object->setMessage(msg);
187}
188
189//ConsoleMethod( SimpleNetObject, setMessage, void, 3, 3, "(string msg)")
190//{
191//   object->setMessage(argv[2]);
192//}
193