Advertisement
Guest User

wtf

a guest
Sep 7th, 2013
1,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.80 KB | None | 0 0
  1. /** Helper functions for broadcasts to all clients and sends to single clients
  2.  *  WORK NEEDED: investigate using templates to reduce the number of functions needed
  3.  *               send<type1, type2, type3>(a, b, c)
  4. **/
  5. void ClientManager::broadcast(Command cmd)
  6. {
  7.     TRAVERSE_AND_LOCK()
  8.         myClient->getConnection()->send(cmd);
  9.         myClient->getConnection()->send((u32int)0);
  10.     UNLOCK_TRAVERSE_END()
  11. }
  12. void ClientManager::send(ClientInstance^ c, Command cmd)
  13. {
  14.     c->getSendLock();
  15.     c->getConnection()->send(cmd);
  16.     c->getConnection()->send((u32int)0);
  17.     c->releaseSendLock();
  18. }
  19. void ClientManager::broadcast(Command cmd, u32int u)
  20. {
  21.     TRAVERSE_AND_LOCK()
  22.         myClient->getConnection()->send(cmd);
  23.         myClient->getConnection()->send((u32int)4);
  24.         myClient->getConnection()->send(u);
  25.     UNLOCK_TRAVERSE_END()
  26. }
  27. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u)
  28. {
  29.     c->getSendLock();
  30.     c->getConnection()->send(cmd);
  31.     c->getConnection()->send((u32int)4);
  32.     c->getConnection()->send(u);
  33.     c->releaseSendLock();
  34. }
  35. void ClientManager::broadcast(Command cmd, System::String^ s)
  36. {
  37.     TRAVERSE_AND_LOCK()
  38.         myClient->getConnection()->send(cmd);
  39.         myClient->getConnection()->send((u32int)(4+s->Length));
  40.         myClient->getConnection()->send(s);
  41.     UNLOCK_TRAVERSE_END()
  42. }
  43. void ClientManager::send(ClientInstance^ c, Command cmd, System::String^ s)
  44. {
  45.     c->getSendLock();
  46.     c->getConnection()->send(cmd);
  47.     c->getConnection()->send((u32int)(4+s->Length));
  48.     c->getConnection()->send(s);
  49.     c->releaseSendLock();
  50. }
  51. void ClientManager::send(ClientInstance^ c, Command cmd, System::String^ s1, u32int i2)
  52. {
  53.     c->getSendLock();
  54.     c->getConnection()->send(cmd);
  55.     c->getConnection()->send((u32int)(8+s1->Length));
  56.     c->getConnection()->send(s1);
  57.     c->getConnection()->send(i2);
  58.     c->releaseSendLock();
  59. }
  60. void ClientManager::broadcast(Command cmd, float f)
  61. {
  62.     TRAVERSE_AND_LOCK()
  63.         myClient->getConnection()->send(cmd);
  64.         myClient->getConnection()->send((u32int)4);
  65.         myClient->getConnection()->send(f);
  66.     UNLOCK_TRAVERSE_END()
  67. }
  68. void ClientManager::send(ClientInstance^ c, Command cmd, float f)
  69. {
  70.     c->getSendLock();
  71.     c->getConnection()->send(cmd);
  72.     c->getConnection()->send((u32int)4);
  73.     c->getConnection()->send(f);
  74.     c->releaseSendLock();
  75. }
  76. void ClientManager::broadcast(Command cmd, u32int u, System::String^ s)
  77. {
  78.     TRAVERSE_AND_LOCK()
  79.         myClient->getConnection()->send(cmd);
  80.         myClient->getConnection()->send((u32int)(8+s->Length));
  81.         myClient->getConnection()->send(u);
  82.         myClient->getConnection()->send(s);
  83.     UNLOCK_TRAVERSE_END()
  84. }
  85. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u, System::String^ s)
  86. {
  87.     c->getSendLock();
  88.     c->getConnection()->send(cmd);
  89.     c->getConnection()->send((u32int)(8+s->Length));
  90.     c->getConnection()->send(u);
  91.     c->getConnection()->send(s);
  92.     c->releaseSendLock();
  93. }
  94. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2)
  95. {
  96.     TRAVERSE_AND_LOCK()
  97.         myClient->getConnection()->send(cmd);
  98.         myClient->getConnection()->send((u32int)8);
  99.         myClient->getConnection()->send(u1);
  100.         myClient->getConnection()->send(u2);
  101.     UNLOCK_TRAVERSE_END()
  102. }
  103. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, u32int u2)
  104. {
  105.     c->getSendLock();
  106.     c->getConnection()->send(cmd);
  107.     c->getConnection()->send((u32int)8);
  108.     c->getConnection()->send(u1);
  109.     c->getConnection()->send(u2);
  110.     c->releaseSendLock();
  111. }
  112.  
  113. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, System::String^ s, u32int u2)
  114. {
  115.     c->getSendLock();
  116.     c->getConnection()->send(cmd);
  117.     c->getConnection()->send((u32int)(12+s->Length));
  118.     c->getConnection()->send(u1);
  119.     c->getConnection()->send(s);
  120.     c->getConnection()->send(u2);
  121.     c->releaseSendLock();
  122. }
  123.  
  124. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2, System::String^ s)
  125. {
  126.     TRAVERSE_AND_LOCK()
  127.         myClient->getConnection()->send(cmd);
  128.         myClient->getConnection()->send((u32int)12+s->Length);
  129.         myClient->getConnection()->send(u1);
  130.         myClient->getConnection()->send(u2);
  131.         myClient->getConnection()->send(s);
  132.     UNLOCK_TRAVERSE_END()
  133. }
  134. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2, u32int u3)
  135. {
  136.     TRAVERSE_AND_LOCK()
  137.         myClient->getConnection()->send(cmd);
  138.         myClient->getConnection()->send((u32int)12);
  139.         myClient->getConnection()->send(u1);
  140.         myClient->getConnection()->send(u2);
  141.         myClient->getConnection()->send(u3);
  142.     UNLOCK_TRAVERSE_END()
  143. }
  144. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2, System::String^ s3, u32int u4)
  145. {
  146.     TRAVERSE_AND_LOCK()
  147.     myClient->getConnection()->send(cmd);
  148.     myClient->getConnection()->send((u32int)16+s3->Length);
  149.     myClient->getConnection()->send(u1);
  150.     myClient->getConnection()->send(u2);
  151.     myClient->getConnection()->send(s3);
  152.     myClient->getConnection()->send(u4);
  153.     UNLOCK_TRAVERSE_END()
  154. }
  155.  
  156. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2, System::String^ s3, System::String^ s4)
  157. {
  158.     TRAVERSE_AND_LOCK()
  159.     myClient->getConnection()->send(cmd);
  160.     myClient->getConnection()->send((u32int)16+s3->Length+s4->Length);
  161.     myClient->getConnection()->send(u1);
  162.     myClient->getConnection()->send(u2);
  163.     myClient->getConnection()->send(s3);
  164.     myClient->getConnection()->send(s4);
  165.     UNLOCK_TRAVERSE_END()
  166. }
  167.  
  168. void ClientManager::broadcast(Command cmd, u32int u1, u32int u2, System::String^ s3, System::String^ s4, System::String^ s5)
  169. {
  170.     TRAVERSE_AND_LOCK()
  171.     myClient->getConnection()->send(cmd);
  172.     myClient->getConnection()->send((u32int)20+s3->Length+s4->Length+s5->Length);
  173.     myClient->getConnection()->send(u1);
  174.     myClient->getConnection()->send(u2);
  175.     myClient->getConnection()->send(s3);
  176.     myClient->getConnection()->send(s4);
  177.     myClient->getConnection()->send(s5);
  178.     UNLOCK_TRAVERSE_END()
  179. }
  180.  
  181. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, u32int u2, System::String^ s3, System::String^ s4)
  182. {
  183.     c->getSendLock();
  184.     c->getConnection()->send(cmd);
  185.     c->getConnection()->send((u32int)16+s3->Length+s4->Length);
  186.     c->getConnection()->send(u1);
  187.     c->getConnection()->send(u2);
  188.     c->getConnection()->send(s3);
  189.     c->getConnection()->send(s4);
  190.     c->releaseSendLock();
  191. }
  192. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, u32int u2, System::String^ s3, u32int u4)
  193. {
  194.     c->getSendLock();
  195.     c->getConnection()->send(cmd);
  196.     c->getConnection()->send((u32int)(16+s3->Length));
  197.     c->getConnection()->send(u1);
  198.     c->getConnection()->send(u2);
  199.     c->getConnection()->send(s3);
  200.     c->getConnection()->send(u4);
  201.     c->releaseSendLock();
  202. }
  203. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, u32int u2, System::String^ s)
  204. {
  205.     c->getSendLock();
  206.     c->getConnection()->send(cmd);
  207.     c->getConnection()->send((u32int)(12+s->Length));
  208.     c->getConnection()->send(u1);
  209.     c->getConnection()->send(u2);
  210.     c->getConnection()->send(s);
  211.     c->releaseSendLock();
  212. }
  213.  
  214. void ClientManager::send(ClientInstance^ c, Command cmd, u32int u1, u32int u2, u32int u3)
  215. {
  216.     c->getSendLock();
  217.     c->getConnection()->send(cmd);
  218.     c->getConnection()->send((u32int)(12));
  219.     c->getConnection()->send(u1);
  220.     c->getConnection()->send(u2);
  221.     c->getConnection()->send(u3);
  222.     c->releaseSendLock();
  223. }
  224. void ClientManager::send(ClientInstance^ c, Command cmd, System::String^ s1, System::String^ s2, System::String^ s3, System::String^ s4 )
  225. {
  226.     c->getSendLock();
  227.     c->getConnection()->send(cmd);
  228.     c->getConnection()->send((u32int)(16+s1->Length+s2->Length+s3->Length+s4->Length));
  229.     c->getConnection()->send(s1);
  230.     c->getConnection()->send(s2);
  231.     c->getConnection()->send(s3);
  232.     c->getConnection()->send(s4);
  233.     c->releaseSendLock();
  234. }
  235. void ClientManager::send(ClientInstance^ c, Command cmd, System::String^ s1, System::String^ s2, System::String^ s3 )
  236. {
  237.     c->getSendLock();
  238.     c->getConnection()->send(cmd);
  239.     c->getConnection()->send((u32int)(12+s1->Length+s2->Length+s3->Length));
  240.     c->getConnection()->send(s1);
  241.     c->getConnection()->send(s2);
  242.     c->getConnection()->send(s3);
  243.     c->releaseSendLock();
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement