/
oshi.php
172 lines (160 loc) · 3.45 KB
/
oshi.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
class Oshi {
/**
* Login
* Return Values:
* 0 = invalid credentials
* 1 = success
* 2 = wrong password
* 3 = email not found
* 4 = banned
*
* @param string $Email
* @param string $Password
* @return int
*/
function UserLogin( $credentials ) {
$result = User::Login( $credentials );
if( $result[ 'userid' ] ) {
//Sessions only work on the declared server handle class :'(
$_SESSION[ 'userid' ] = $result[ 'userid' ];
}
return $result[ 'res' ];
}
/**
* Logout (void)
* Destroys the session
*
*/
function UserLogout() {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = New User( $_SESSION[ 'userid' ] );
$user->Logout();
unset( $_SESSION[ 'userid' ] );
}
}
/**
* Checks the connection status (void)
* Returns true on connected,
* false if the session has ended
*
* @return boolean
*/
function CheckConnection() {
if( isset( $_SESSION[ 'userid' ] ) ) {
return true;
}
return false;
}
/**
* Create a new Game
* Returns true on success, false on error
*
* @return bool
*/
function CreateGame() {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = New User( $_SESSION[ 'userid' ] );
return $user->CreateGame();
}
return false;
}
/**
* Join an existing game
* Arguments: the id of the game we want to connect to
* Returns true on success, false on error
*
* @param int gameId
* @return bool
*/
function JoinGame( $gameId ) {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = new User( $_SESSION[ 'userid' ] );
return $user->JoinGame( $gameId );
}
return false;
}
/*
* Quit the game (no winner)
*
*/
function QuitGame() {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = new User( $_SESSION[ 'userid' ] );
$game = $user->GetCurrentGame();
$game->Close();
}
}
/**
* Join an existing game
* Arguments: the id of the game we want to connect to
*
* @return GameWrapper
*/
function GetCurrentGame() {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = new User( $_SESSION[ 'userid' ] );
return $user->GetCurrentGameWrapper();
}
}
/**
* Gets a list of online users
* Returns a list of UserWrapper objects
*
* @return UserWrapper[]
*/
function GetOnlineUsers() {
if( isset( $_SESSION[ 'userid' ] ) ) {
return User::GetOnlineUsers();
}
else {
return array();
}
}
/**
* Gets a list of open games
* Returns a list of GameWrapper objects
*
* @return GameWrapper[]
*/
function GetOpenGames() {
if( isset( $_SESSION[ 'userid' ] ) ) {
return Game::GetOpenGames();
}
else {
return array();
}
}
/**
* When idle, call this at least once per minute
* to confirm online status
*
* @return boolean
*/
function ConfirmIdle() {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = New User( $_SESSION[ 'userid' ] );
$user->ConfirmIdle();
return true;
}
return false;
}
/**
* When idle, call this at least once per minute
* to confirm online status
*
* @return boolean
*/
function MovePawn( $pawnId, $x, $y ) {
if( isset( $_SESSION[ 'userid' ] ) ) {
$user = new User( $_SESSION[ 'userid' ] );
$game = $user->GetCurrentGame();
if( $game->IsUserTurn( $user ) ) {
return $game->MovePawn( $pawnId, $x, $y);
}
//throw new SoapFault("Server", "first check" );
}
return false;
}
}
?>