source: branches/posledni/inc/registration_limit.php

Last change on this file was 596, checked in by george, 16 years ago
  • Přidáno: Třída pro systém omezování počtu registrací. Automatické povolování registrací dle předchozího počtu hráčů online vůči zadané požadované hodnotě.
File size: 2.6 KB
Line 
1<?php
2
3class RegistrationLimit
4{
5 var $db;
6 var $Server;
7 var $Config;
8
9 function __construct($db, $Server, $Config)
10 {
11 $this->db = $db;
12 $this->Server = $Server;
13 $this->Config = $Config;
14 }
15
16 function Update()
17 {
18 $AccountOnlineCount = $this->Server->RealmOnline();
19 $AccountCount = $this->Server->AccountCount();
20
21 $this->db->select_db($this->Config['Database']['Database']);
22 $DbResult = $this->db->query('SELECT * FROM `CharacterOnlineHistory` WHERE `Date` = CURDATE()');
23 if($DbResult->num_rows > 0)
24 {
25 // Update max, min
26 $this->db->query('UPDATE `CharacterOnlineHistory` SET `Max` = GREATEST(`Max`, '.$AccountOnlineCount.'), `Min` = LEAST(`Min`, '.$AccountOnlineCount.'), `AccountCount` = '.$AccountCount.' WHERE `Date` = CURDATE()');
27 echo($this->db->error);
28 } else
29 $this->db->query('INSERT INTO `CharacterOnlineHistory` (`Max`, `Min`, `Date`, `AccountCount`) VALUES ('.$AccountOnlineCount.', '.$AccountOnlineCount.', CURDATE(), '.$AccountCount.')');
30 }
31
32 function GetFreeRegistrationCount()
33 {
34 $AccountCount = $this->Server->AccountCount();
35
36 $this->db->select_db($this->Config['Database']['Database']);
37 $DbResult = $this->db->query('SELECT * FROM `CharacterOnlineHistory` WHERE `Date` = DATE_SUB(CURDATE(), INTERVAL 1 DAY)');
38 if($DbResult->num_rows > 0)
39 {
40 $Yesterday = $DbResult->fetch_assoc();
41 } else
42 $Yesterday = array('Max' => 0, 'AccountCount' => 0);
43
44 $NextDayFreeRegistration = $this->Config['Mangos']['RequiredOnlinePlayers'] - $Yesterday['Max'];
45 if($NextDayFreeRegistration < 0) $NextDayFreeRegistration = 0;
46 $NextDayUsedRegistration = $AccountCount - $Yesterday['AccountCount'];
47 $FreeRegistration = $NextDayFreeRegistration - $NextDayUsedRegistration;
48 if($FreeRegistration < 0) $FreeRegistration = 0;
49 return($FreeRegistration);
50 }
51
52 function GetPerDeyRegistrationCount()
53 {
54 $AccountCount = $this->Server->AccountCount();
55
56 $this->db->select_db($this->Config['Database']['Database']);
57 $DbResult = $this->db->query('SELECT * FROM `CharacterOnlineHistory` WHERE `Date` = DATE_SUB(CURDATE(), INTERVAL 1 DAY)');
58 if($DbResult->num_rows > 0)
59 {
60 $Yesterday = $DbResult->fetch_assoc();
61 } else
62 $Yesterday = array('Max' => 0, 'AccountCount' => 0);
63
64 $NextDayFreeRegistration = $this->Config['Mangos']['RequiredOnlinePlayers'] - $Yesterday['Max'];
65 if($NextDayFreeRegistration < 0) $NextDayFreeRegistration = 0;
66 return($NextDayFreeRegistration);
67 }
68}
69
70?>
Note: See TracBrowser for help on using the repository browser.