Просмотр файла games/LuckyDice.php

Размер файла: 13.73Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', true);
  7. $phpbb_root_path = './';
  8. include($phpbb_root_path . 'extension.inc');
  9. include($phpbb_root_path . 'common.' . $phpEx);
  10. include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_luckydice.' . $phpEx);
  11.  
  12. //
  13. // Start session management
  14. //
  15. $userdata = session_pagestart($user_ip, PAGE_INDEX);
  16. init_userprefs($userdata);
  17. //
  18. // End session management
  19. //
  20.  
  21. $user_id = $userdata['user_id'];
  22. $username = $userdata['username'];
  23.  
  24. if ( !$userdata['session_logged_in'] )
  25. {
  26. $redirect = "LuckyDice.$phpEx";
  27. header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
  28. }
  29.  
  30. $bet = ( isset($_POST['bet']) ) ? $_POST['bet'] : '0';
  31. $played = $board_config['luckydice_played'];
  32. $taken = $board_config['luckydice_taken'];
  33. $given = $board_config['luckydice_given'];
  34.  
  35. // check if game is disabled, ifnot then continue:
  36. if( $board_config['luckydice_enable'] == '0' )
  37. {
  38. message_die(GENERAL_MESSAGE, ''.$lang['game_disabled'].'');
  39. }
  40. // START GAME
  41. $page_title = 'LuckyDice';
  42.  
  43. $mainsub = $lang['game_explanation1'] . $lang['game_explanation2'] . $lang['game_explanation3'] . $lang['game_explanation4'];
  44.  
  45. $game = '<SCRIPT LANGUAGE="JavaScript">'
  46. .'function DisabSub(frm)'
  47. .'{'
  48. .' var btn = frm.play;'
  49. .'btn.disabled = true;'
  50. .'return true;'
  51. .'}'
  52. .'</SCRIPT> ';
  53.  
  54.  
  55. //version 1.4.0::
  56. //-- max bets a day --
  57. $stop = false;
  58. //check if this feature is enabled: (the config value has to be bigger than 0 (zero)
  59. if( $board_config['luckydice_betsaday'] > 0 )
  60. {
  61. //this function is enabled::
  62. //verify the user his stats (reset counter if needed)
  63. $userBets = $userdata['luckydice_bets'];
  64. //first the timer:
  65. $timerstarted = $userdata['luckydice_time'];
  66. $currenttime = time(); //--> these are UNIX timestamps !!
  67. $diffTime = 86400; //24 hours in seconds.
  68. if( ($currenttime - $timerstarted) >= $diffTime )
  69. {
  70. //counter reset --> update db and let him play:
  71. $sql = "UPDATE " . USERS_TABLE . " SET luckydice_time='0' WHERE user_id = ".$user_id;
  72. if(! ($db->sql_query($sql)) )
  73. {
  74. message_die(GENERAL_ERROR, 'Fatal Error Resetting Counter!', '', __LINE__, __FILE__ ,$sql );
  75. }
  76. $sql = "UPDATE " . USERS_TABLE . " SET luckydice_bets='0' WHERE user_id = ".$user_id;
  77. if(! ($db->sql_query($sql)) )
  78. {
  79. message_die(GENERAL_ERROR, 'Fatal Error Resetting Amount of Bets for the Day!', '', __LINE__, __FILE__ ,$sql );
  80. }
  81. $userBets = 0;
  82. }
  83. if( $userBets >= $board_config['luckydice_betsaday'] )
  84. {
  85. //stop user from playing --> show a message.
  86. $game = sprintf($lang['toomanyplays'], $board_config['luckydice_betsaday']);
  87. $stop = true;
  88. }
  89. }
  90.  
  91.  
  92. if(! $stop ) //--> user has played too many times already, just show the message!
  93. {
  94. //---------------
  95.  
  96.  
  97. if ( $bet == '0')
  98. {
  99. $main = $lang['home1'] . $lang['home2'] . $lang['home3'];
  100.  
  101. $game .= '<tr>
  102. <td class="row1"><form method="POST" onSubmit="return DisabSub(this);">';
  103. $game .= '<input type="text" name="bet" class="liteoption"><br/>';
  104. $game .= '<input type="submit" class="liteoption" value="Поехали" name="Поехали" ></form></td>
  105. </tr><tr>
  106. <td class="row1"> '.$lang['maxbetis'].''. $board_config['luckydice_maxbet'] .' '. $board_config['points_name'] .'';
  107. $game .= '<br>'.$lang['youhave'] . $userdata['user_points'] .' '. $board_config['points_name'] .'.';
  108. $game .= '<br>'. $lang['played'] . $played . $lang['_times'] .'<br>' . $lang['taken'] . $taken .' '. $board_config['points_name'] .' ' . $lang['given'] . $given .' '. $board_config['points_name'];
  109. }
  110. else
  111. {
  112. //version 1.4.0::
  113. //-- max bets a day --
  114. //check if this feature is enabled: (the config value has to be bigger than 0 (zero)
  115. if( $board_config['luckydice_betsaday'] > 0 )
  116. {
  117. //update the user's amount of bets for the day (update the counter if needed) ::
  118. $newTime = $userdata['luckydice_time'];
  119. if( $userdata['luckydice_time'] == 0 )
  120. {
  121. $newTime = time();
  122. }
  123. $newBets = $userdata['luckydice_bets'] + 1;
  124. $sql = "UPDATE " . USERS_TABLE . " SET luckydice_bets='".$newBets."'
  125. , luckydice_time='".$newTime."'
  126. WHERE user_id = ".$user_id;
  127. if(! ($db->sql_query($sql)) )
  128. {
  129. message_die(GENERAL_ERROR, 'Fatal Error Increasing Counter!', '', __LINE__, __FILE__ ,$sql );
  130. }
  131. }
  132. //-----------------------
  133. if(! is_numeric($bet) )
  134. {
  135. message_die(GENERAL_MESSAGE, ''.$lang['error_values'].'');
  136. }
  137. if( $bet < '0')
  138. {
  139. message_die(GENERAL_MESSAGE, ''.$lang['zero_error_values'].'');
  140. }
  141. if( $bet > $userdata['user_points'] )
  142. {
  143. message_die(GENERAL_MESSAGE, ''.$lang['error_money'].'');
  144. }
  145. if( $bet > $board_config['luckydice_maxbet'] )
  146. {
  147. message_die(GENERAL_MESSAGE, ''.$lang['error_maxbet'].'');
  148. }
  149. // where are the dices ??
  150. $dice1_place = rand(1,6);
  151. $dice2_place = rand(1,6);
  152. // what's the top-number ??
  153. $dice1_num = rand(1,6);
  154. $dice2_num = rand(1,6);
  155. // what are the bonusses ??
  156. $bunus_hi_lo = rand(1,2);
  157. if( $bonus_hi_lo == 1 )
  158. {
  159. $bonus1 = rand(1,3);
  160. $bonus2 = rand(4,6);
  161. }
  162. else
  163. {
  164. $bonus1 = rand(4,6);
  165. $bonus2 = rand(1,3);
  166. }
  167. switch($bonus1){
  168. case 1:
  169. $bonus1_pic = 'one.gif';
  170. break;
  171. case 2:
  172. $bonus1_pic = 'two.gif';
  173. break;
  174. case 3:
  175. $bonus1_pic = 'three.gif';
  176. break;
  177. case 4:
  178. $bonus1_pic = 'four.gif';
  179. break;
  180. case 5:
  181. $bonus1_pic = 'five.gif';
  182. break;
  183. case 6:
  184. $bonus1_pic = 'six.gif';
  185. break;
  186. }
  187. switch($bonus2){
  188. case 1:
  189. $bonus2_pic = 'one.gif';
  190. break;
  191. case 2:
  192. $bonus2_pic = 'two.gif';
  193. break;
  194. case 3:
  195. $bonus2_pic = 'three.gif';
  196. break;
  197. case 4:
  198. $bonus2_pic = 'four.gif';
  199. break;
  200. case 5:
  201. $bonus2_pic = 'five.gif';
  202. break;
  203. case 6:
  204. $bonus2_pic = 'six.gif';
  205. break;
  206. }
  207.  
  208. // all possibilities:
  209. if( $dice1_place == $dice2_place )
  210. {
  211. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  212. }
  213. if( $dice1_num == $dice2_num )
  214. {
  215. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  216. }
  217. if( $dice1_place == $dice1_num )
  218. {
  219. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  220. }
  221. if( $dice2_place == $dice2_num )
  222. {
  223. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  224. }
  225. if( $dice1_place == $dice2_num )
  226. {
  227. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  228. }
  229. if( $dice2_place == $dice1_num )
  230. {
  231. $win_count = ( isset($win_count) ) ? ($win_count + 1) : 1;
  232. }
  233. //
  234. // the possibilities:
  235.  
  236. $game .= '<tr>
  237. <td class="row1"><a href="'. append_sid("LuckyDice.".$phpEx) .'" class="nav">'.$lang['again'].'</a><br/>';
  238. $game .= '<form method="POST" onSubmit="return DisabSub(this);"><input class="liteoption" type="text" name="bet" value="'.$bet.'"><br/>';
  239. $game .= '<input type="submit" class="liteoption" value="Поехали" name="Поехали"></form><span class="gensmall"> '.$lang['maxbetis'].''. $board_config['luckydice_maxbet'] .' '. $board_config['points_name'] .'</div>';
  240. switch ($win_count)
  241. {
  242. case 6: // the perfect, bet X5
  243. $win_numb = ( $dice1_place );
  244. if( ($win_numb != $bonus1) || ($win_numb != $bonus2) )
  245. {
  246. $winnings = floor( $bet * $board_config['luckydice_winperfect'] );
  247. $l_main .= $lang['winperfect'] . $winnings .' '. $board_config['points_name'].'.';
  248. $money_str = ' + '.$winnings;
  249. }
  250. else if( ($win_numb == $bonus1) )
  251. {
  252. $winnings = floor( $bet * $board_config['luckydice_winperfect'] * $board_config['luckydice_bonussmall'] );
  253. $l_main .= $lang['winbonussmall'] . $winnings .' '. $board_config['points_name'].'.';
  254. $money_str = ' + '.$winnings;
  255. }
  256. else if( ($win_numb == $bonus2) )
  257. {
  258. $winnings = floor( $bet * $board_config['luckydice_winperfect'] * $board_config['luckydice_bonusbig'] );
  259. $l_main .= $lang['winbonusbig'] . $winnings .' '. $board_config['points_name'].'s';
  260. $money_str = ' + '.$winnings;
  261. }
  262. break;
  263. case 3:// a triple, bet X3
  264. $winnings = floor( $bet * $board_config['luckydice_wintriple'] );
  265. $l_main .= $lang['wintriple'] . $winnings .' '. $board_config['points_name'].'.';
  266. $money_str = ' + '.$winnings;
  267. break;
  268. // 2 pairs, bet X2
  269. case 2:
  270. $winnings .= floor( $bet * $board_config['luckydice_windouble'] );
  271. $l_main = $lang['windouble'] . $winnings .' '. $board_config['points_name'].'.';
  272. $money_str = ' + '.$winnings;
  273. break;
  274. case 1: // no winning, no lose (1 pair)
  275. $l_main .= $lang['winpair'];
  276. $winnings = $bet;
  277. break;
  278. default:// if the user lost...
  279. $l_main = $lang['lose'];
  280. $money_str = ' - '.$bet;
  281. break;
  282. } //switch end
  283. // show the javascript of the rolling dices:
  284. $main = "<!-- Keith Drakard (kif@irt.org) v0.10 on 9th September 98
  285. -->
  286. <SCRIPT LANGUAGE=\"JavaScript\"><!-- //
  287. // global variables
  288. var noof_dice= 4;
  289. var rolled= new Array(noof_dice);
  290. var imgpath = 'images/lucky_dice/';
  291. function roll(x) {
  292. // roll the dice
  293. if (x> 0) {
  294. // carry on rolling:
  295. x--;
  296. for (d=0; d<noof_dice; d++) {
  297. // on last roll, show the right number:
  298. if( x == 0 ){
  299. // show dices there id.
  300. switch( d )
  301. {
  302. case 0 : rolled[d]= ".$dice1_place."; break;
  303. case 1 : rolled[d]= ".$dice1_num."; break;
  304. case 2 : rolled[d]= ".$dice2_place."; break;
  305. case 3 : rolled[d]= ".$dice2_num."; break;
  306. }
  307. // show the 'winnings'-text:
  308. Win_text.innerHTML = \"".$l_main."\";
  309. } else{
  310. rolled[d] = rand(6);
  311. }
  312. document.images[\"die\"+d].src= dice[rolled[d]].src;
  313. }
  314. setTimeout('roll('+x+')', 200);
  315. }
  316. }
  317. function preload() {
  318. if (document.images) {
  319. dice= new makeArray(7);
  320. dice[0].src= imgpath+\"blank.gif\";
  321. dice[1].src= imgpath+\"one.gif\";
  322. dice[2].src= imgpath+\"two.gif\";
  323. dice[3].src= imgpath+\"three.gif\";
  324. dice[4].src= imgpath+\"four.gif\";
  325. dice[5].src= imgpath+\"five.gif\";
  326. dice[6].src= imgpath+\"six.gif\";
  327. for (d=0; d<noof_dice; d++) {
  328. document.images[\"die\"+d].src= dice[rand(6)].src;
  329. }
  330. } else {
  331. alert(\"Sorry, this example needs to run on a browser which supports the image object.\");
  332. }
  333. }
  334. // The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
  335. // See: http://www.msc.cornell.edu/~houle/javascript/randomizer.html
  336. // NOTE:- modified by Kif to produce integers between 1-limit
  337. rnd.today=new Date(); rnd.seed=rnd.today.getTime();
  338. function rnd() {
  339. rnd.seed = (rnd.seed*9301+49297) % 233280;
  340. return rnd.seed/(233280.0);
  341. }
  342. function rand(limit) { return Math.ceil(rnd()*limit); }
  343. // The following function was written by Martin Webb at http://www.irt.org/
  344. function makeArray(n) {
  345. this.length= n; for (i=0; i<n; i++) { this[i] = new Image(); }
  346. return this;
  347. }
  348. //--></SCRIPT>
  349. <div class='body'>
  350. Небольшое поощрение если:<br/> <img src=\"images/lucky_dice/".$bonus1_pic."\"><br>
  351. Главный бонус при: <br/> <img src=\"images/lucky_dice/".$bonus2_pic."\">
  352. <img src=\"images/lucky_dice/blank.gif\" name=\"die0\"><img src=\"images/lucky_dice/blank.gif\" name=\"die1\"><img src=\"images/lucky_dice/blank.gif\" name=\"die2\"><img src=\"images/lucky_dice/blank.gif\" name=\"die3\"><br>
  353. </tr>
  354. <tr>
  355. <td class='row1'><a id=\"Win_text\"></a></td></tr>
  356. <script language=\"JavaScript\"><!--//
  357. preload();
  358. roll( 20 ); // how many times must the dices roll??
  359. //-->"
  360. ."</script>";
  361. // end javascript
  362.  
  363. // update the winnings/loses:
  364. if( isset($money_str) )
  365. {
  366. $newmoney = $userdata['user_points'] . $money_str;
  367. $sql = 'UPDATE '. USERS_TABLE .' SET user_points = '. $newmoney .' WHERE user_id = '. $userdata['user_id'];
  368. if(! ($result = $db->sql_query($sql)) ) { message_die(GENERAL_ERROR, 'Fatal Error Getting Points Information!', '', __LINE__, __FILE__ ,$sql); }
  369. }
  370. // update 'played', 'given', 'taken':
  371. $newplayed = $played + 1;
  372. $newgiven = (isset($winnings)) ? ($given + $winnings) : $given;
  373. $newtaken = $taken + $bet;
  374. $sql1 = 'UPDATE '. CONFIG_TABLE .' SET config_value = '. $newplayed .' WHERE config_name = "luckydice_played"';
  375. if(! $result = $db->sql_query($sql1) )
  376. { message_die(GENERAL_ERROR, 'Fatal Error Updating luckydice_played!', '', __LINE__, __FILE__ ,$sql1); }
  377. $sql2 = 'UPDATE '. CONFIG_TABLE .' SET config_value = '. $newgiven .' WHERE config_name = "luckydice_given"';
  378. if(! $result = $db->sql_query($sql2) )
  379. { message_die(GENERAL_ERROR, 'Fatal Error Updating luckydice_given!', '', __LINE__, __FILE__ ,$sql2); }
  380. $sql3 = 'UPDATE '. CONFIG_TABLE .' SET config_value = '. $newtaken .' WHERE config_name = "luckydice_taken"';
  381. if(! $result = $db->sql_query($sql3) )
  382. { message_die(GENERAL_ERROR, 'Fatal Error Updating luckydice_taken!', '', __LINE__, __FILE__ ,$sql3); }
  383. }
  384.  
  385. //version 1.4.0
  386. } //end of if( $stop )
  387. //-------------
  388.  
  389. // END GAME
  390.  
  391. $location = ' -> <a href="'.append_sid("LuckyDice.".$phpEx).'" class="nav">'.$page_title.'</a>';
  392.  
  393.  
  394. //
  395. // Start page output
  396. //
  397. include($phpbb_root_path . 'includes/page_header.' . $phpEx);
  398.  
  399. $template->assign_vars(array(
  400. 'LDLOCATION' => $location,
  401. 'TITLE' => $page_title,
  402. 'MAIN' => $main,
  403. 'GAME' => $game,
  404. 'SUB' => $mainsub,
  405. ));
  406. $template->assign_block_vars('', array());
  407. $template->set_filenames(array(
  408. 'body' => 'luckydice_body.tpl')
  409. );
  410.  
  411.  
  412. // Generate page
  413. $template->pparse('body');
  414.  
  415. include($phpbb_root_path . 'includes/page_tail.' . $phpEx);
  416.  
  417. ?>