Guest User

input_main.cpp

a guest
Aug 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "constants.h"
  3. #include "config.h"
  4. #include "utils.h"
  5. #include "desc_client.h"
  6. #include "desc_manager.h"
  7. #include "buffer_manager.h"
  8. #include "packet.h"
  9. #include "protocol.h"
  10. #include "char.h"
  11. #include "char_manager.h"
  12. #include "item.h"
  13. #include "item_manager.h"
  14. #include "cmd.h"
  15. #include "shop.h"
  16. #include "shop_manager.h"
  17. #include "safebox.h"
  18. #include "regen.h"
  19. #include "battle.h"
  20. #include "exchange.h"
  21. #include "questmanager.h"
  22. #include "profiler.h"
  23. #include "messenger_manager.h"
  24. #include "party.h"
  25. #include "p2p.h"
  26. #include "affect.h"
  27. #include "guild.h"
  28. #include "guild_manager.h"
  29. #include "log.h"
  30. #include "banword.h"
  31. #include "empire_text_convert.h"
  32. #include "unique_item.h"
  33. #include "building.h"
  34. #include "locale_service.h"
  35. #include "gm.h"
  36. #include "spam.h"
  37. #include "ani.h"
  38. #include "motion.h"
  39. #include "OXEvent.h"
  40. #include "locale_service.h"
  41. #include "HackShield.h"
  42. #include "XTrapManager.h"
  43. #include "DragonSoul.h"
  44.  
  45. extern void SendShout(const char * szText, BYTE bEmpire);
  46. extern int g_nPortalLimitTime;
  47.  
  48. static int __deposit_limit()
  49. {
  50. return (1000*10000); // 1ΓµΈΈ
  51. }
  52.  
  53. void SendBlockChatInfo(LPCHARACTER ch, int sec)
  54. {
  55. if (sec <= 0)
  56. {
  57. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Γ¤ΖΓ ±έΑφ »σΕΒΐΤ΄Ο΄Ω."));
  58. return;
  59. }
  60.  
  61. long hour = sec / 3600;
  62. sec -= hour * 3600;
  63.  
  64. long min = (sec / 60);
  65. sec -= min * 60;
  66.  
  67. char buf[128+1];
  68.  
  69. if (hour > 0 && min > 0)
  70. snprintf(buf, sizeof(buf), LC_TEXT("%d ½Γ°£ %d ΊΠ %d ΓΚ µΏΎΘ Γ¤ΖΓ±έΑφ »σΕΒΐΤ΄Ο΄Ω"), hour, min, sec);
  71. else if (hour > 0 && min == 0)
  72. snprintf(buf, sizeof(buf), LC_TEXT("%d ½Γ°£ %d ΓΚ µΏΎΘ Γ¤ΖΓ±έΑφ »σΕΒΐΤ΄Ο΄Ω"), hour, sec);
  73. else if (hour == 0 && min > 0)
  74. snprintf(buf, sizeof(buf), LC_TEXT("%d ΊΠ %d ΓΚ µΏΎΘ Γ¤ΖΓ±έΑφ »σΕΒΐΤ΄Ο΄Ω"), min, sec);
  75. else
  76. snprintf(buf, sizeof(buf), LC_TEXT("%d ΓΚ µΏΎΘ Γ¤ΖΓ±έΑφ »σΕΒΐΤ΄Ο΄Ω"), sec);
  77.  
  78. ch->ChatPacket(CHAT_TYPE_INFO, buf);
  79. }
  80.  
  81. EVENTINFO(spam_event_info)
  82. {
  83. char host[MAX_HOST_LENGTH+1];
  84.  
  85. spam_event_info()
  86. {
  87. ::memset( host, 0, MAX_HOST_LENGTH+1 );
  88. }
  89. };
  90.  
  91. typedef boost::unordered_map<std::string, std::pair<unsigned int, LPEVENT> > spam_score_of_ip_t;
  92. spam_score_of_ip_t spam_score_of_ip;
  93.  
  94. EVENTFUNC(block_chat_by_ip_event)
  95. {
  96. spam_event_info* info = dynamic_cast<spam_event_info*>( event->info );
  97.  
  98. if ( info == NULL )
  99. {
  100. sys_err( "block_chat_by_ip_event> <Factor> Null pointer" );
  101. return 0;
  102. }
  103.  
  104. const char * host = info->host;
  105.  
  106. spam_score_of_ip_t::iterator it = spam_score_of_ip.find(host);
  107.  
  108. if (it != spam_score_of_ip.end())
  109. {
  110. it->second.first = 0;
  111. it->second.second = NULL;
  112. }
  113.  
  114. return 0;
  115. }
  116.  
  117. bool SpamBlockCheck(LPCHARACTER ch, const char* const buf, const size_t buflen)
  118. {
  119. extern int g_iSpamBlockMaxLevel;
  120.  
  121. if (ch->GetLevel() < g_iSpamBlockMaxLevel)
  122. {
  123. spam_score_of_ip_t::iterator it = spam_score_of_ip.find(ch->GetDesc()->GetHostName());
  124.  
  125. if (it == spam_score_of_ip.end())
  126. {
  127. spam_score_of_ip.insert(std::make_pair(ch->GetDesc()->GetHostName(), std::make_pair(0, (LPEVENT) NULL)));
  128. it = spam_score_of_ip.find(ch->GetDesc()->GetHostName());
  129. }
  130.  
  131. if (it->second.second)
  132. {
  133. SendBlockChatInfo(ch, event_time(it->second.second) / passes_per_sec);
  134. return true;
  135. }
  136.  
  137. unsigned int score;
  138. const char * word = SpamManager::instance().GetSpamScore(buf, buflen, score);
  139.  
  140. it->second.first += score;
  141.  
  142. if (word)
  143. sys_log(0, "SPAM_SCORE: %s text: %s score: %u total: %u word: %s", ch->GetName(), buf, score, it->second.first, word);
  144.  
  145. extern unsigned int g_uiSpamBlockScore;
  146. extern unsigned int g_uiSpamBlockDuration;
  147.  
  148. if (it->second.first >= g_uiSpamBlockScore)
  149. {
  150. spam_event_info* info = AllocEventInfo<spam_event_info>();
  151. strlcpy(info->host, ch->GetDesc()->GetHostName(), sizeof(info->host));
  152.  
  153. it->second.second = event_create(block_chat_by_ip_event, info, PASSES_PER_SEC(g_uiSpamBlockDuration));
  154. sys_log(0, "SPAM_IP: %s for %u seconds", info->host, g_uiSpamBlockDuration);
  155.  
  156. LogManager::instance().CharLog(ch, 0, "SPAM", word);
  157.  
  158. SendBlockChatInfo(ch, event_time(it->second.second) / passes_per_sec);
  159.  
  160. return true;
  161. }
  162. }
  163.  
  164. return false;
  165. }
  166.  
  167. enum
  168. {
  169. TEXT_TAG_PLAIN,
  170. TEXT_TAG_TAG, // ||
  171. TEXT_TAG_COLOR, // |cffffffff
  172. TEXT_TAG_HYPERLINK_START, // |H
  173. TEXT_TAG_HYPERLINK_END, // |h ex) |Hitem:1234:1:1:1|h
  174. TEXT_TAG_RESTORE_COLOR,
  175. };
  176.  
  177. int GetTextTag(const char * src, int maxLen, int & tagLen, std::string & extraInfo)
  178. {
  179. tagLen = 1;
  180.  
  181. if (maxLen < 2 || *src != '|')
  182. return TEXT_TAG_PLAIN;
  183.  
  184. const char * cur = ++src;
  185.  
  186. if (*cur == '|') // ||΄Β |·Ξ Η¥½ΓΗΡ΄Ω.
  187. {
  188. tagLen = 2;
  189. return TEXT_TAG_TAG;
  190. }
  191. else if (*cur == 'c') // color |cffffffffblahblah|r
  192. {
  193. tagLen = 2;
  194. return TEXT_TAG_COLOR;
  195. }
  196. else if (*cur == 'H') // hyperlink |Hitem:10000:0:0:0:0|h[ΐΜΈ§]|h
  197. {
  198. tagLen = 2;
  199. return TEXT_TAG_HYPERLINK_START;
  200. }
  201. else if (*cur == 'h') // end of hyperlink
  202. {
  203. tagLen = 2;
  204. return TEXT_TAG_HYPERLINK_END;
  205. }
  206.  
  207. return TEXT_TAG_PLAIN;
  208. }
  209.  
  210. void GetTextTagInfo(const char * src, int src_len, int & hyperlinks, bool & colored)
  211. {
  212. colored = false;
  213. hyperlinks = 0;
  214.  
  215. int len;
  216. std::string extraInfo;
  217.  
  218. for (int i = 0; i < src_len;)
  219. {
  220. int tag = GetTextTag(&src[i], src_len - i, len, extraInfo);
  221.  
  222. if (tag == TEXT_TAG_HYPERLINK_START)
  223. ++hyperlinks;
  224.  
  225. if (tag == TEXT_TAG_COLOR)
  226. colored = true;
  227.  
  228. i += len;
  229. }
  230. }
  231.  
  232. int ProcessTextTag(LPCHARACTER ch, const char * c_pszText, size_t len)
  233. {
  234. return 0;//BETEKINT
Advertisement
Add Comment
Please, Sign In to add comment