function makeCommonPassword()
 {
     $Security1 = '';
     for ($i = 0; $i < SECURITY_LENGTH; $i++) {
         $Security1 .= chr(mt_rand(48, 122));
     }
     $Security2 = '';
     for ($i = 0; $i < SECURITY_LENGTH; $i++) {
         $Security2 .= chr(mt_rand(48, 122));
     }
     // 清理 120 秒以前的安全码
     $this->db->delete('security', array('DATE_ADD(MakeDate,INTERVAL 120 SECOND)<' => date('Y-m-d H:i:s')));
     $data = array('Security1' => $Security1, 'Security2' => $Security2, 'MakeDate' => date('Y-m-d H:i:s'));
     $this->db->insert('security', $data);
     $id = $this->db->insert_id();
     $ret = array($id, AzDG_crypt($Security1), AzDG_crypt($Security2));
     return $ret;
 }
Exemple #2
0
 function login($username, $password, $lanip, $port)
 {
     // 产生安全码,用于登陆以后的操作
     if ($this->makeSecurity($username)) {
         $this->db->select('*')->from('user')->where('UserName', $username)->where('Password', $password);
         $query = $this->db->get();
         if ($query->num_rows() > 0) {
             $row = $query->row_array();
             $playTimes = $row['Win'] + $row['Lose'] + $row['Draw'];
             $disconnect = $row['GameTimes'] - $playTimes;
             if ($disconnect > $row['DisconnectTimes'] and $disconnect % 2 == 0) {
                 $reduce = true;
                 $row['DisconnectTimes'] = $row['GameTimes'] - $playTimes;
                 $row['Score']--;
                 $data = array('Score' => $row['Score'], 'DisconnectTimes' => $row['DisconnectTimes']);
                 $this->db->where('UserName', $username);
                 $this->db->update('user', $data);
             } else {
                 $reduce = false;
             }
             $this->db->select('UserName')->from('online')->where('UserName', $username);
             $query_online = $this->db->get();
             $data = array('UserName' => $username, 'Name' => $row['Name'], 'IP' => getUserIp(), 'LANIP' => $lanip, 'Port' => $port, 'LastTime' => date('Y-m-d H:i:s'));
             if ($query_online->num_rows() > 0) {
                 $this->db->where('UserName', $username);
                 $this->db->update('online', $data);
             } else {
                 $this->db->insert('online', $data);
             }
             $data = array('LastLogin' => date('Y-m-d H:i:s'));
             $this->db->where('UserName', $username);
             $this->db->update('user', $data);
             // 100 天未登陆者,用户数据将被删除!
             //$this->db->delete('user', array('DATE_ADD(LastLogin,INTERVAL 100 DAY)<' => date('Y-m-d H:i:s')));
             $ret = array($row['Email'], $row['UserClass'], $row['Face'], $row['Name'], $row['Sex'], $row['Age'], $row['Country'], $row['State'], $row['City'], $row['Win'], $row['Lose'], $row['Draw'], $row['GameTimes'], $row['Score'], getUserIp(), AzDG_crypt($row['Security1']), AzDG_crypt($row['Security2']));
             if ($reduce) {
                 $ret[] = '请注意:由于您又断线了 2 次,所以扣除 1 分! 当前分数: ' . $row['Score'];
             }
         } else {
             $ret = false;
         }
     } else {
         $ret = false;
     }
     $CI = get_instance();
     $CI->load->model('online_model');
     $CI->online_model->removeInactive();
     return $ret;
 }