Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. <?PHP
  2. echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?>';
  3. $config_ini = parse_ini_file('../config/config.ini');
  4. include('../config/config.php');
  5. $name = strtolower(stripslashes(trim($_REQUEST['name'])));
  6. if(empty($name))
  7. {
  8. echo '<font color="red">Please enter new character name.</font>';
  9. exit;
  10. }
  11.  
  12. //first word can't be:
  13. $first_words_blocked = array('gm ','cm ', 'god ','tutor ', "'", '-');
  14. //names blocked:
  15. $names_blocked = array('gm','cm', 'god', 'tutor');
  16. //name can't contain:
  17. $words_blocked = array('gamemaster', 'game master', 'game-master', "game'master", ' ', '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor');
  18. $temp = strspn("$name", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '");
  19. if($temp != strlen($name))
  20. {
  21. echo '<font color="red">Name contains illegal letters. Use only: <b>qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- \'</b></font>';
  22. exit;
  23. }
  24. if(strlen($name) > 25)
  25. {
  26. echo '<font color="red">Too long name. Max. lenght <b>25</b> letters.</font>';
  27. exit;
  28. }
  29. foreach($names_blocked as $word)
  30. if($word == $name)
  31. {
  32. echo '<font color="red">Blocked names:<b> '.$names_blocked[0];
  33. if(count($names_blocked) > 1)
  34. foreach($names_blocked as $word)
  35. if($word != $names_blocked[0])
  36. echo ','.$word;
  37. echo '</b></font>';
  38. exit;
  39. }
  40. foreach($config['site']['monsters'] as $word)
  41. if($word == $name)
  42. {
  43. echo '<font color="red"><b>You can not use monster name.</b></font>';
  44. exit;
  45. }
  46. foreach($config['site']['npc'] as $word)
  47. if($word == $name)
  48. {
  49. echo '<font color="red"><b>You can not use NPC name.</b></font>';
  50. exit;
  51. }
  52. foreach($first_words_blocked as $word)
  53. if($word == substr($name, 0, strlen($word)))
  54. {
  55. echo '<font color="red">First letters in name can\'t be:<b> '.$first_words_blocked[0];
  56. if(count($first_words_blocked) > 1)
  57. foreach($first_words_blocked as $word)
  58. if($word != $first_words_blocked[0])
  59. echo ','.$word;
  60. echo '</b></font>';
  61. exit;
  62. }
  63. if(substr($name, -1) == "'" || substr($name, -1) == "-")
  64. {
  65. echo '<font color="red">Last letter can\'t be <b>\'</b> and <b>-</b></font>';
  66. exit;
  67. }
  68. foreach($words_blocked as $word)
  69. if (!(strpos($name, $word) === false))
  70. {
  71. echo '<font color="red">Name can\'t cointain words:<b> '.$words_blocked[0];
  72. if(count($words_blocked) > 1)
  73. foreach($words_blocked as $word)
  74. if($word != $words_blocked[0])
  75. echo ','.$word;
  76. echo '</b></font>';
  77. exit;
  78. }
  79. for($i = 0; $i < strlen($name); $i++)
  80. if($name[$i] == $name[($i+1)] && $name[$i] == $name[($i+2)])
  81. {
  82. echo '<font color="red">Name can\'t contain 3 same letters one by one.</font><br /><font color="green"><u>Good:</u> M<b>oo</b>nster</font><font color="red"><br />Wrong: M<b>ooo</b>nster</font>';
  83. exit;
  84. }
  85. for($i = 0; $i < strlen($name); $i++)
  86. if($name[$i-1] == ' ' && $name[$i+1] == ' ')
  87. {
  88. echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>G e s ior</b></font>';
  89. exit;
  90. }
  91. if(substr($name, 1, 1) == ' ')
  92. {
  93. echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>G esior</b></font>';
  94. exit;
  95. }
  96. if(substr($name, -2, 1) == " ")
  97. {
  98. echo '<font color="red">Use normal name format.</font><br /><font color="green"><u>Good:</u> <b>Gesior</b></font><font color="red"><br />Wrong: <b>Gesio r</b></font>';
  99. exit;
  100. }
  101. else
  102. //connect to DB
  103. $server_config = parse_ini_file($config_ini['server_path'].'config.lua');
  104. if(isset($server_config['mysqlHost']))
  105. {
  106. //new (0.2.6+) ots config.lua file
  107. $mysqlhost = $server_config['mysqlHost'];
  108. $mysqluser = $server_config['mysqlUser'];
  109. $mysqlpass = $server_config['mysqlPass'];
  110. $mysqldatabase = $server_config['mysqlDatabase'];
  111. $sqlitefile = $server_config['sqliteDatabase'];
  112. }
  113. elseif(isset($server_config['sqlHost']))
  114. {
  115. //old (0.2.4) ots config.lua file
  116. $mysqlhost = $server_config['sqlHost'];
  117. $mysqluser = $server_config['sqlUser'];
  118. $mysqlpass = $server_config['sqlPass'];
  119. $mysqldatabase = $server_config['sqlDatabase'];
  120. $sqlitefile = $server_config['sqliteDatabase'];
  121. }
  122. // loads #####POT mainfile#####
  123. include('../pot/OTS.php');
  124. // PDO and POT connects to database
  125. $ots = POT::getInstance();
  126. if($server_config['sqlType'] == "mysql")
  127. $ots->connect(POT::DB_MYSQL, array('host' => $mysqlhost, 'user' => $mysqluser, 'password' => $mysqlpass, 'database' => $mysqldatabase) );
  128. elseif($server_config['sqlType'] == "sqlite")
  129. $ots->connect(POT::DB_SQLITE, array('database' => $config_ini['server_path'].$sqlitefile));
  130. $name_db = new OTS_Player();
  131. $name_db->find($name);
  132. if($name_db->isLoaded())
  133. echo '<font color="red"><b>Player with this name already exist.</b></font>';
  134. else
  135. echo '<font color="green">Good. Your name will be:<br />"<b>'.ucwords($name).'</b>"</font>';
  136.  
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement