forked from xiaosier/sae-php-channel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
51 lines (47 loc) · 1.11 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require( dirname(__FILE__).'/render.php' );
require( dirname(__FILE__).'/game.php' );
$user = $_COOKIE['u'];
if (!$user) {
$user = uniqid();
setcookie("u",$user);
}
$game_key = $_REQUEST['g'];
if (!$game_key) {
$game_key = $user;
$stor_mess = array(
'userX' => $user,
'userO' => null,
'board' => str_repeat(" ",9),
'moveX' => true,
'winner' => null,
'winning_board'=>null,
);
$game = new Game($game_key,$stor_mess);
$game->put();
} else {
$game = Game::get_by_key_name($game_key);
if (!$game->userO) {
$game ->userO = $user;
$game->put();
}
}
$game_link = '/?g='.$game_key;
if ( $game ) {
$channel_instance = new SaeChannel();
$token = $channel_instance->createChannel($user.$game_key);
$game_update_instance = new GameUpdater($game);
$initial_message = $game_update_instance->get_game_message();
} else {
die('No such game');
}
$render_message = array(
'token' => $token,
'me' => $user,
'game_key' => $game_key,
'game_link' => $game_link,
'initial_message' => $initial_message,
);
$template_file = 'index.tpl';
$ret = render_template($template_file, $render_message);
echo($ret);