This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
279 lines (255 loc) · 7.71 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
//imports
require_once 'includes/sqlconn.php';
require_once 'includes/functions.php';
//constants
$protocolVersion = 19;
//get headers
$header = getallheaders();
$toprint = array();
//read post data
$postdata = file_get_contents('php://input');
//default player data
$userName = 'nouser';
//TODO: implement site, if ua is not 'osu!'
header('cho-token: '.'yomama'); //TODO: implement tokens
header('cho-protocol: '.$protocolVersion);
if (!isset($header['osu-token'])) {
//parse post data
$lines = explode("\n", $postdata);
if (count($lines) != 4) {
DieError(-5);
} else {
//do checks
$userName = $lines[0];
$passHash = $lines[1];
$user = GetUserByName($userName);
if (CheckUserPassword($user, $passHash) === false) DieError(-1);
$userId = $user['id'];
$userRank = $user['status'];
$userName = $user['username']; //in case casing is different
if ($userRank == 0) ActivateUser($userId);
if ($userRank == -1) DieError(-3); //banned
//TODO: implement these things
$pp = 0; //TODO: implement pp
$globalRank = 0;
$totalScore = GetTotalScoreFromId($user['id']);
$accuracy = GetAccuracyFromId($user['id']);
$playCount = GetPlaycountFromId($user['id']);
//5,000 / 3 * (4n^3 - 3n^2 - n) + 1.25 * 1.8^(n - 60)
$experience = 0;//$totalscore; //actually, nvm
$toprint = array_merge(
CreatePacket(92, 0), //ban status/time
CreatePacket(5, $userId), //user id
CreatePacket(75, $protocolVersion), //bancho protocol version
CreatePacket(71, $userRank), //user rank (supporter etc)
CreatePacket(72, array(1, 2)), //friend list
CreatePacket(83, array( //local player
'id' => $userId,
'playerName' => $userName,
'utcOffset' => 0 + 24,
'country' => 0,
'playerRank' => $userRank,
'longitude' => 0,
'latitude' => 0,
'globalRank' => $globalRank,
)),
CreatePacket(11, array( //more local player data
'id' => $userId,
'bStatus' => 0, //byte
'string0' => '', //String
'string1' => '', //string
'mods' => 0, //int
'playmode' => 0, //byte
'int0' => 0, //int
'score' => $totalScore, //long score
'accuracy' => $accuracy, //float accuracy
'playcount' => $playCount, //int playcount
'experience' => $experience, //long experience
'int1' => $globalRank, //int global rank?
'pp' => $pp, //short pp if set, will use?
)), //*/
CreatePacket(83, array( //bancho bob
'id' => 3,
'playerName' => GetUserById(3)['username'],
'utcOffset' => 0 + 24,
'country' => 1,
'playerRank' => 0,
'longitude' => 0,
'latitude' => 0,
'globalRank' => 0,
)),
CreatePacket(96, array(0, $userId)), //TODO: list of players
CreatePacket(89, null),
//foreach player online, packet 12 or 95
CreatePacket(64, '#osu'), //main channel
CreatePacket(64, '#news'),
CreatePacket(65, array('#osu', 'Main channel', 2147483647 - 1)), //secondary channel
CreatePacket(65, array('#news', 'This will contain announcements and info, while beta lasts.', 1)),
CreatePacket(65, array('#kfc', 'Kawaii friends club', 0)), //secondary channel
CreatePacket(65, array('#aqn', 'cuz fuck yeah', 1337)),
//CreatePacket(105, "HoLLy_HaCKeR eyes have awakened.\nGo pray to your mommy, banhammer is on it's way.") //scary msg
//players
//GetOnlinePlayersPackets(),
CreatePacket(07, array('BanchoBob', 'This is a test message! First step to getting chat working!', '#osu', 3))
);
}
} else {
//Get shit from database i guess
$userId = 1;
$userName = "HoLLy_HaCKeR";
$userRank = 15;
$globalRank = 1;
//TODO: implement other packets
//TODO: create packets where currenttime-lastlogintime < 60?
$toprint = array_merge(
CreatePacket(83, array( //local player
'id' => $userId,
'playerName' => $userName,
'utcOffset' => 0 + 24,
'country' => 0,
'playerRank' => $userRank,
'longitude' => 0,
'latitude' => 0,
'globalRank' => $globalRank,
))
);
}
SetLastActiveForId($userId);
echo implode(array_map("chr", $toprint));
function GetOnlinePlayersPackets() {
$players = GetOnlinePlayers();
$return = array();
foreach ($players as $player) {
$newarray = ConvertPlayer($player);
$return = array_merge($toreturn, CreatePacket(83, $newarray));
}
return $toreturn;
}
function ConvertPlayer($player) {
return array(
'id' => $player['id'],
'playerName' => $player['username'],
'utcOffset' => 0 + 24,
'country' => 1,
'playerRank' => $player['status'],
'longitude' => 0,
'latitude' => 0,
'globalRank' => 0,
);
}
function DieError($err) {
die(implode(array_map("chr", CreatePacket(5, $err))));
}
function GetLongBytes($long) {
$value = $long;
$highMap = 0xffffffff00000000;
$lowMap = 0x00000000ffffffff;
$higher = ($value & $highMap) >>32;
$lower = $value & $lowMap;
$packed = pack('NN', $higher, $lower);
return array_reverse(unpack('C*', $packed));
}
function ULeb128($string) { //TODO: use proper ULEB128
if ($string == '') return array(0);
$toreturn = array();
$toreturn = array_merge(
array(11, strlen($string)),
unpack('C*', $string));
//var_dump($toreturn);
return $toreturn;
}
function CreatePacket($type, $data = null) {
$toreturn = '';
$length = 0;
switch ($type) {
//string
case 24: //show custom, orange notification
case 64: //Main channel
case 66: //remove channel?
case 105: //show scary msg
$toreturn = ULeb128($data);
break;
//empty
case 23:
case 50: //something with match-confirm
case 59: //something with chat channels?
case 80: //Sneaky Shizzle
$toreturn = array();
break;
//Class17 (player data 02)
case 83: //local player
$toreturn = array();
$toreturn = array_merge(
unpack('C*', pack('L*', $data['id'])),
ULeb128($data['playerName']), //TODO: fix names
unpack('C*', pack('C*', $data['utcOffset'])),
unpack('C*', pack('C*', $data['country'])),
unpack('C*', pack('C*', $data['playerRank'])),
unpack('C*', pack('f*', $data['longitude'])),
unpack('C*', pack('f*', $data['latitude'])),
unpack('C*', pack('L*', $data['globalRank']))
);
break;
//Class19 (player data 01)
case 11: //some player thing
$toreturn = array_merge(
unpack('C*', pack('L*', $data['id'])),
unpack('C*', pack('C*', $data['bStatus'])),
ULeb128($data['string0']),
ULeb128($data['string1']),
unpack('C*', pack('L*', $data['mods'])),
unpack('C*', pack('C*', $data['playmode'])),
unpack('C*', pack('L*', $data['int0'])),
GetLongBytes($data['score']),
unpack('C*', pack('f*', $data['accuracy'])),
unpack('C*', pack('L*', $data['playcount'])),
GetLongBytes($data['experience']),
unpack('C*', pack('L*', $data['int1'])),
unpack('C*', pack('S*', $data['pp']))
);
break;
//Class20 (string, string, short)
case 65: //chat channel with title
$toreturn = array_merge(
ULeb128($data[0]),
ULeb128($data[1]),
unpack('C*', pack('S*', $data[2]))
);
break;
//chat Message
case 07:
$toreturn = array_merge(
ULeb128($data[0]),
ULeb128($data[1]),
ULeb128($data[2]),
unpack('C*', pack('I', $data[3]))
);
break;
//int[] (short length, int[length])
case 72: //friend list, int[]
case 96: //list of online players
$l1 = unpack('C*', pack('S', sizeof($data)));
$toreturn = array();
foreach ($data as $key => $value) {
$toreturn = array_merge($toreturn, unpack('C*', pack('I', $value)) );
}
$toreturn = array_merge($l1, $toreturn);
break;
//int32
case 5: //user id
case 71: //user rank
case 75: //cho protocol
case 92: //ban status
default:
$toreturn = unpack('C*', pack('L*', $data));
break;
}
return array_merge(
unpack('S*', pack("L*", $type)), //type
array(0), //unused byte
unpack('C*', pack('L', sizeof($toreturn))), //length
$toreturn //data
);
}
?>