protected function connected($user)
 {
     socket_getpeername($user->socket, $user->ip);
     //save the client ip
     $ip = Ip::find($user->ip);
     $user->ip = $ip[1] . $ip[2] . '-' . date('H:i:s');
     //file_put_contents(__DIR__.'/log.log', serialize($ip));
     //exit;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = ['slot' => 'Integer', 'memory' => 'Integer|Min:128|Max:10240', 'status' => 'Required', 'ip' => 'Required', 'port' => 'Integer|Min:1024|Max:65534|Required', 'displayName' => '', 'user' => 'Required|Exists:users,id'];
     $v = Validator::make(Input::all(), $rules);
     if ($v->passes()) {
         $ip_port = new GameserverIp();
         $ip_port->port = Input::get('port');
         $ip = Ip::find(Input::get('ip'));
         $ip_port->ip()->associate($ip);
         $ip_port->save();
         $user = User::find(Input::get('user'));
         $game = Game::find(Input::get('game'));
         $gameserver = new Gameserver();
         $gameserver->fill(Input::all());
         $gameserver->ipport()->associate($ip_port);
         $gameserver->user()->associate($user);
         $gameserver->game()->associate($game);
         $gameserver->save();
         return Redirect::action('GameserverController@index');
     } else {
         return Redirect::action('GameserverController@create')->withErrors($v->getMessageBag());
     }
 }
예제 #3
0
파일: IpType.php 프로젝트: oyoy8629/test
 public static function find($ip)
 {
     $data = static::ip($ip);
     $data = json_decode($data, true);
     return ['data' => implode(":", Ip::find($ip)), 'ip' => $ip, 'type' => $data['data']['type'], 'text' => in_array($data['data']['type'], array_keys(static::$type)) ? static::$type[$data['data']['type']] : "未知"];
 }
function testIpLocation()
{
    $this->assertEquals(['中国', '河南', '郑州', ''], Ip::find('1.192.94.203'));
    $this->assertEquals(['中国', '浙江', '杭州', ''], Ip::find('110.75.115.70'));
}
예제 #5
0
/**
如果没有登录的时候访问学校,且学校又没指定,则根据当前的用户访问ip
获得所在城市的第一个学校
*/
function getDefaultCollegeid()
{
    $cityInfo = Ip::find(get_client_ip());
    return empty($cityInfo['2']) ? '武汉' : $cityInfo['2'];
}