[Orxonox-commit 1860] r6577 - in code/branches/chat/src/libraries/network: . packet

smerkli at orxonox.net smerkli at orxonox.net
Sun Mar 21 23:22:04 CET 2010


Author: smerkli
Date: 2010-03-21 23:22:04 +0100 (Sun, 21 Mar 2010)
New Revision: 6577

Modified:
   code/branches/chat/src/libraries/network/ChatListener.h
   code/branches/chat/src/libraries/network/Host.h
   code/branches/chat/src/libraries/network/packet/Chat.cc
Log:
Nothing really, just skimming through code, adding comments...

Modified: code/branches/chat/src/libraries/network/ChatListener.h
===================================================================
--- code/branches/chat/src/libraries/network/ChatListener.h	2010-03-21 19:26:46 UTC (rev 6576)
+++ code/branches/chat/src/libraries/network/ChatListener.h	2010-03-21 22:22:04 UTC (rev 6577)
@@ -37,9 +37,11 @@
     class _NetworkExport ChatListener : virtual public OrxonoxClass
     {
         public:
+	    /* constructor, destructor */
             ChatListener();
             virtual ~ChatListener() {}
 
+            /* What to do with incoming chat */
             virtual void incomingChat(const std::string& message, unsigned int senderID) = 0;
     };
 }

Modified: code/branches/chat/src/libraries/network/Host.h
===================================================================
--- code/branches/chat/src/libraries/network/Host.h	2010-03-21 19:26:46 UTC (rev 6576)
+++ code/branches/chat/src/libraries/network/Host.h	2010-03-21 22:22:04 UTC (rev 6577)
@@ -48,7 +48,7 @@
 */
 class _NetworkExport Host{
   private:
-    //TODO add theese functions or adequate
+    //TODO add these functions or adequate
     //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
     //virtual bool sendChat(packet::Chat *chat)=0;
     virtual bool queuePacket(ENetPacket *packet, int clientID)=0;

Modified: code/branches/chat/src/libraries/network/packet/Chat.cc
===================================================================
--- code/branches/chat/src/libraries/network/packet/Chat.cc	2010-03-21 19:26:46 UTC (rev 6576)
+++ code/branches/chat/src/libraries/network/packet/Chat.cc	2010-03-21 22:22:04 UTC (rev 6577)
@@ -36,6 +36,8 @@
 namespace packet {
 
 #define   PACKET_FLAGS_CHAT PacketFlag::Reliable
+
+/* Some lengths */
 #define   _PACKETID         0
 const int _PLAYERID     =   _PACKETID + sizeof(Type::Value);
 #define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
@@ -44,12 +46,22 @@
 Chat::Chat( const std::string& message, unsigned int playerID )
  : Packet()
 {
+  /* Add chat flag to packet flags */
   flags_ = flags_ | PACKET_FLAGS_CHAT;
+
+  /* set message length to length of input string + 1 */
   messageLength_ = message.length()+1;
+
+  /* allocate memory for the data */
   data_=new unsigned char[ getSize() ];
+
   *(Type::Value *)(data_ + _PACKETID ) = Type::Chat;
   *(unsigned int *)(data_ + _PLAYERID ) = playerID;
   *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
+
+  /* cast the hell out of the message string, and copy it into the 
+   * data buffer. 
+   */
   memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), messageLength_ );
 }
 




More information about the Orxonox-commit mailing list