Advertisement
Guest User

Untitled

a guest
Feb 11th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. function serverCmdSetNameColor(%cl,%id)
  2. {
  3.     if(strPos("1234567",%id) == -1)
  4.     {
  5.         // Give the players a list of valid colors
  6.         messageClient(%cl,'',"\c0You many only enter a number 1 to 7.");
  7.         messageClient(%cl,'',"\c0Here are the valid colors: \c00 \c11 \c22 \c33 \c44 \c55 \c66 \c77");
  8.     }
  9.     else
  10.     {
  11.         // "\c" @ %color doesnt work but this does
  12.         eval("%color = \"\\c" @ %id @ "\";");
  13.         %cl.nameColor = %color;
  14.        
  15.         // Tell them that they can use clan prefix
  16.         messageClient(%cl,'',"\c2Your normal name will appear as " @ %color @ "this color\c2 in the chat.");
  17.         messageClient(%cl,'',"\c2To automatically set that color, use this clan prefix: \c7c{" @ %id @ "}");
  18.     }
  19. }
  20.  
  21. function serverCmdMessageSent(%cl,%msg)
  22. {
  23.     // This function recreates the entire chat
  24.     %msg  = stripMLControlChars(trim(%msg));
  25.     %cnt  = getWordCount(%msg);
  26.     %spam = %cl.isSpamming;
  27.     %time = getSimTime();
  28.    
  29.     // Remaking chat so we need to block words
  30.     if($Pref::Server::ETardFilter)
  31.     {
  32.         %filter = strReplace($Pref::Server::ETardList,",","\t");
  33.         %count  = getFieldCount(%filter);
  34.        
  35.         for(%i = 0; %i < %count; %i++)
  36.         {
  37.             %word = getField(%filter,%i);
  38.            
  39.             // This will check space-requiring filters
  40.             if(strPos(" " @ %msg @ " ",%word) != -1)
  41.             {
  42.                 messageClient(%cl,'',"\c5This is a civilized game. Please use full words.");
  43.                 return;
  44.             }
  45.         }
  46.     }
  47.    
  48.     if(%msg $= %cl.lastChatText && %time - %cl.lastChatTime < 15000)
  49.     {
  50.         // An admin gets sent this warning message
  51.         messageClient(%cl,'',"\c5Do not repeat yourself.");
  52.        
  53.         if(!%cl.isAdmin && !%spam)
  54.         {
  55.             // They get flood protected for 10 seconds
  56.             %cl.isSpamming       = 1;
  57.             %cl.spamProtectStart = %time;
  58.            
  59.             schedule(10000,0,eval,%cl @ ".isSpamming = 0;");
  60.         }
  61.     }
  62.    
  63.     if(!%cl.isAdmin && !%spam)
  64.     {
  65.         if(%cl.spamMessageCount == 4)
  66.         {
  67.             // They get flood protected for 10 seconds
  68.             %cl.isSpamming       = 1;
  69.             %cl.spamProtectStart = %time;
  70.            
  71.             schedule(10000,0,eval,%cl @ ".isSpamming = 0;");
  72.         }
  73.         else
  74.         {
  75.             // They can only send four lines every 10s
  76.             %cl.spamMessageCount++;
  77.             schedule(10000,0,eval,%cl @ ".spamMessageCount--;");
  78.         }
  79.     }
  80.    
  81.     // Tells them that they're spamming
  82.     if(%cl.isSpamming)
  83.     {
  84.         spamAlert(%cl);
  85.         return;
  86.     }
  87.    
  88.     // Remaking chat so we need to parse links
  89.     for(%i = 0; %i < %cnt; %i++)
  90.     {
  91.         %word = getWord(%msg,%i);
  92.         %end  = getSubStr(%word,7,strLen(%word));
  93.        
  94.         // Added in check for ":" which broke tags
  95.         if(getSubStr(%word,0,7) $= "http://" && strPos(%end,":") == -1)
  96.             %word = "<a:" @ %end @ ">" @ %end @ "</a>\c6";
  97.        
  98.         if(%i) %new = %new SPC %word;
  99.         else   %new = %word;
  100.     }
  101.    
  102.     // Send messages to clients the proper way
  103.     %msg  = %new;
  104.     %name = %cl.nameColor @ %cl.getPlayerName();
  105.     %pre  = %cl.clanPrefix;
  106.     %suf  = %cl.clanSuffix;
  107.     %all  = '\c7%1\c3%2\c7%3\c6: %4' @ "\c7" @ %pre @ "\c3" @ %name @ "\c7" @ %suf @ "\c6: " @ %msg;
  108.    
  109.     %cl.lastChatText = %msg;
  110.     %cl.lastChatTime = %time;
  111.    
  112.     commandToAll('chatMessage',%cl,'','',%all,%pre,%name,%suf,%msg);
  113. }
  114.  
  115. package ColoredNames
  116. {
  117.     function GameConnection::onConnectRequest(%this,%a,%b,%c,%d,%e,%f,%g)
  118.     {
  119.         %length = strLen(%d);
  120.        
  121.         // Has to start with "c{" and end with "}"
  122.         if(getSubStr(%d,0,2) $= "c{" && getSubStr(%d,%length - 1,1) $= "}")
  123.         {
  124.             // After the "c{" must be a color id 0 - 7
  125.             if(strPos("01234567",getSubStr(%d,2,1)) != -1)
  126.             {
  127.                 // "\c" @ %color doesnt work but this does
  128.                 eval("%color = \"\\c" @ getSubStr(%d,2,%length - 3) @ "\";");
  129.                 %this.nameColor = %color;
  130.                
  131.                 %d = "";
  132.             }
  133.         }
  134.        
  135.         Parent::onConnectRequest(%this,%a,%b,%c,%d,%e,%f,%g);
  136.     }
  137. };
  138. activatePackage(ColoredNames);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement