Advertisement
Guest User

Blockland net bug test code

a guest
Mar 20th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. // Throw off huffman encoding by using "infrequent" characters
  2. // see http://www.dspguide.com/ch27/3.htm
  3.  
  4. function hmGenTable()
  5. {
  6.     %infq = "!\"#$%&'()*+-?/:;<>=@~|{}^[]\\_`";
  7.     $hm::infq_t = strlen(%infq);
  8.    
  9.     for(%i = 0; %i < $hm::infq_t; %i++)
  10.         $hm::infq_t[%i] = getSubStr(%infq, %i, 1);
  11. }
  12.  
  13. function hmStr(%len)
  14. {
  15.     if($hm::infq_t $= "")
  16.         hmGenTable();
  17.    
  18.     for(%i = 0; %i < %len; %i++)
  19.         %rand = %rand @ $hm::infq_t[getRandom($hm::infq_t - 1)];
  20.    
  21.     return %rand;
  22. }
  23.  
  24. function spamPacketsToAll()
  25. {
  26.     cancel($spamPackets);
  27.  
  28.     // Packet size is 1023; we want to be some amount under that.
  29.     // Spam a bunch of remote command events to fill up the buffer.
  30.     // Ghosting also fills it so optimally this will run on an empty server.
  31.     // Note: net string length limited to 256
  32.     // Note: not counting packet headers
  33.    
  34.     while(%bits < (900 << 3))
  35.     {
  36.         // event: tag (~4 bytes) + 5 bits argc + strings
  37.         // writeString: bit (encode flag) + byte (length) + string bytes (no null)
  38.        
  39.         // Simulate a bunch of random sized events being sent (a busy server)
  40.        
  41.         %len = getRandom(64, 128);
  42.         %bits += (46 + (%len << 3));
  43.        
  44.         commandtoall('spam', hmStr(%len));
  45.     }
  46.    
  47.     // Run each tick
  48.    
  49.     $spamPackets = schedule(32, 0, spamPacketsToAll);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement