Compare commits

...

313 Commits

Author SHA1 Message Date
solis
0550222eed
fixed non working english letters 2018-12-10 04:16:26 +10:30
Sunpy
a0053de311 Updated submodule 2018-10-09 11:02:49 +02:00
Sunpy
848dacf621 Reworked config structure 2018-10-09 10:54:35 +02:00
Sunpy
5111b6b05f Updated submodule 2018-10-09 10:53:26 +02:00
Sunpy
9ad8d5779e Dirty fix for match size init 2018-09-10 23:35:59 +02:00
Sunpy
71f5a8c4d0 THEY!!! IT IS NOT HARD! 2018-09-10 22:45:03 +02:00
Sunpy
768971e240 Updated submodules 2018-09-02 01:45:33 +02:00
Giuseppe Guerra
a248b4032c Opsie wopsie 2018-08-14 00:04:46 +02:00
Giuseppe Guerra
cb6d828fd9 Add !bloodcat command, automatically send bloodcat links in #spectator 2018-08-14 00:04:04 +02:00
Giuseppe Guerra
925d55bb16 🔼 1.13.7 🔼 2018-08-12 17:19:12 +02:00
Giuseppe Guerra
4e97c717f5 Properly handle exceptions in periodic loops 2018-08-12 17:18:12 +02:00
Giuseppe Guerra
f11708d463 Removed useless log 2018-08-12 17:08:43 +02:00
Giuseppe Guerra
4c3427fd76 Read main menu icon from main_menu_icons table 2018-08-12 17:03:18 +02:00
Giuseppe Guerra
a3ab53e108 🔼 1.13.6 🔼 2018-08-04 23:11:26 +02:00
Giuseppe Guerra
74cfadb261 Fix uncaught userAlreadyInChannelException in channel __init__ 2018-08-04 23:11:07 +02:00
Giuseppe Guerra
c09c7b5d96 ??? 2018-08-04 23:10:38 +02:00
Giuseppe Guerra
56c1dcc48a 🔼 1.13.5 🔼 2018-08-04 20:13:30 +02:00
Giuseppe Guerra
1b9224fc79 Fix broken sentry client 2018-08-04 19:58:22 +02:00
Giuseppe Guerra
887836045d Send match history link after the first match 2018-08-04 19:49:38 +02:00
Giuseppe Guerra
cb2d1e74f7 The ascension of the Madonna (the 15th of August is approaching) 2018-08-04 19:26:42 +02:00
Giuseppe Guerra
7f283d9aa2 Forbid #spect_ and #multi_ manual join from game clients 2018-08-04 19:16:40 +02:00
Giuseppe Guerra
333cfca806 Professional debuggingTM 2018-08-04 19:13:29 +02:00
Giuseppe Guerra
1dc37ecb77 Send alert when doing !mp join from an IRC client 2018-08-04 18:53:04 +02:00
Giuseppe Guerra
a456508ed3 Add !mp settings single 2018-08-04 18:52:48 +02:00
Giuseppe Guerra
66acc12099 Add !mp scorev and !mp help 2018-08-04 18:47:31 +02:00
Giuseppe Guerra
a9fc15d524 Add support for EZ in !mp mods 2018-08-04 18:36:32 +02:00
Giuseppe Guerra
02b08d3024 Add AGPL license agreement 2018-07-13 12:30:23 +02:00
Giuseppe Guerra
d8c6fa4993 Updated submodule common 2018-07-13 12:28:20 +02:00
Giuseppe Guerra
fe05aa7ace 🔼 1.13.4 🔼 2018-07-04 17:26:58 +02:00
Giuseppe Guerra
79ecdbcd44 Deprecated telegram 2fa 2018-07-04 17:01:22 +02:00
Giuseppe Guerra
fd47bc6e32 Updated submodule common 2018-07-04 17:01:06 +02:00
Giuseppe Guerra
1a4e952e4f Ignore .pyx files in .pyenv 2018-04-13 23:38:05 +02:00
Sunpy
2cd69a9a63 Merged with upstream 2018-04-08 21:20:26 +02:00
Giuseppe Guerra
ea4e2bd4fd Pin cython to 0.27.3 2018-04-03 12:40:45 +02:00
Giuseppe Guerra
508f6b507a Add .pyenv to .gitignore 2018-04-03 12:38:32 +02:00
Giuseppe Guerra
e89fbe7604 Pin requirements 2018-04-03 12:37:29 +02:00
Giuseppe Guerra
05694c5d87 Handle invalidUserException when calling fokabot commands 2018-04-02 18:19:47 +02:00
Giuseppe Guerra
198bdb9997 * 2018-04-02 12:15:22 +02:00
Giuseppe Guerra
473a2e1f2d 🔼 1.13.3 🔼 2018-03-23 21:38:24 +01:00
Giuseppe Guerra
a809008e55 Improvements to fokabot commands 2018-03-23 21:37:47 +01:00
Giuseppe Guerra
201593ea02 Handle empty arguments in fokabot !mp commands 2018-03-23 21:28:24 +01:00
Giuseppe Guerra
3275d31861 Handle matches with no name 2018-03-23 21:28:13 +01:00
Giuseppe Guerra
05eead0e1a Handle empty chat messages 2018-03-23 21:27:48 +01:00
Giuseppe Guerra
8bdc56faf6 🔼 1.13.2 🔼 2018-03-23 21:05:06 +01:00
Giuseppe Guerra
745a833aab Fix !mp close not working 2018-03-23 21:03:27 +01:00
Giuseppe Guerra
dcad5c5736 git.zxq.co -> zxq.co 2018-03-23 20:59:44 +01:00
Giuseppe Guerra
c1f8ca8ed3 Removed timeoutTime and checkTime args from usersTimeoutCheckLoop 2018-03-23 20:59:30 +01:00
Giuseppe Guerra
e0d54f49d1 Add empty match cleanup job 2018-03-23 20:59:04 +01:00
Sunpy
c2af1b9772 Updated submodules 2018-02-16 20:12:52 +01:00
Sunpy
a99bf0c74b Unhardcoded hardcoded code :) 2018-02-14 20:03:36 +01:00
Sunpy
f0fa00b181 Additional configuration 2018-02-14 19:59:43 +01:00
Sunpy
956aa8161f Updated submodules 2018-02-14 18:31:28 +01:00
Sunpy
08b367812f Use constant values in commands 2018-02-14 18:16:09 +01:00
Sunpy
0722c91018 Fixed mpClose function return message 2018-02-14 17:53:14 +01:00
Sunpy
f0e8223b5c Updated submodules 2018-02-14 17:52:27 +01:00
Sunpy
27a5f9c000 Use whatever account that is in id 999 as bot 2018-02-14 17:44:37 +01:00
Sunpy
29db61fd12 Updated submodules 2018-02-12 21:16:33 +01:00
Giuseppe Guerra
e63a85e4a4 I knew a threaded bancho server was going to be a bad idea... 2017-12-21 18:58:56 +01:00
Giuseppe Guerra
050c1d5fe8 Fix AiAe.exe willing to break stuff 2017-12-08 13:08:54 +01:00
Giuseppe Guerra
90cd4634fd Le melanzane fritte sono poco digeribili 2017-12-05 21:17:09 +01:00
Giuseppe Guerra
e3f1bc05e9 Changed !rtx privileges to ADMIN_KICK_USERS 2017-12-04 23:34:04 +01:00
Giuseppe Guerra
0939ec972c Merge remote-tracking branch 'origin/master' 2017-10-31 13:11:21 +01:00
Giuseppe Guerra
2ef89daf4c Force ASCII encoding in /api/v1/fokabotMessage 2017-10-31 13:11:01 +01:00
Morgan Bazalgette
bb8ccf8c85
make chat mods red, too 2017-10-09 15:24:34 +02:00
Giuseppe Guerra
dc90f506bd Fix np bug again 2017-09-22 22:57:21 +02:00
Giuseppe Guerra
2f9179362c Fix !last not returning pp for taiko scores 2017-09-22 22:46:40 +02:00
Giuseppe Guerra
3dfb1228ee Merge branch 'tourney-mp-room-changes' of ripple/pep.py into master 2017-09-09 12:48:30 +02:00
Morgan Bazalgette
c4123eb636
fix positional argument exception meme 2017-09-09 12:42:49 +02:00
Morgan Bazalgette
e3e46a34ec
Notify the chat when the match has been completed. 2017-09-09 12:30:25 +02:00
Morgan Bazalgette
3ed837dc96
In tourney rooms, send a message in the chat when the ready status changes. 2017-09-09 12:25:51 +02:00
Nyo
48534bb551 Fix typo 🤔 2017-08-26 22:28:05 +02:00
goeo_
36d701eac1 Make the irc gateway not receive the last empty line on multiline messages. 2017-08-20 18:01:18 +03:00
goeo_
60fe2bc56e Make !mp close close the match even if the user is only in the match's channel and not in the match 2017-08-20 17:22:47 +03:00
goeo_
b8baddf694 Make the irc gateway compatible with multi-line messages 2017-08-20 17:10:15 +03:00
Giuseppe Guerra at an airport
018da5c0a2 Removed chat filters because goeo is a dickhead 2017-08-15 08:43:33 +02:00
Giuseppe Guerra at an airport
0a2ca07198 Bump version 2017-08-12 21:36:16 +02:00
Giuseppe Guerra at an airport
34e7a332e6 Add spect lock back 2017-08-12 21:29:27 +02:00
Giuseppe Guerra
8d97227965 Fix race condition while iterating over clients 2017-08-12 19:07:28 +02:00
Giuseppe Guerra at an airport
176775f8f3 Remove extra locks 2017-08-12 18:56:31 +02:00
Giuseppe Guerra at an airport
0329847477 Don't start spectating unexisting users if user id is negative 2017-08-12 08:56:39 +02:00
Giuseppe Guerra at an airport
b24b4ee88d Remove _streamLock 2017-08-12 08:49:55 +02:00
Giuseppe Guerra
e40acd335b Fix some commands not being triggered 2017-08-11 23:17:33 +02:00
Giuseppe Guerra
ce75f5ee99 Remove _chatLock and _internalLock 2017-08-11 22:19:39 +02:00
Giuseppe Guerra
29359ad4fd Fix various bugs with multiplayer teams and mp commands 2017-08-11 22:04:25 +02:00
Giuseppe Guerra
def4891008 Fix wrong commands being triggered if they have the same letters at the beginning 2017-08-11 01:36:25 +02:00
Giuseppe Guerra
5d73682a71 Fix username with spaces breaking commands 2017-08-11 01:33:14 +02:00
Giuseppe Guerra
0229fc4e65 Mp commands now require USER_TOURNAMENT_STAFF privilege 2017-08-11 01:19:30 +02:00
Giuseppe Guerra
05c4c89002 Merge branch 'master' of git.zxq.co:ripple/pep.py 2017-08-11 01:14:45 +02:00
Giuseppe Guerra
02b266f229 Add !mp settings 2017-08-11 01:14:21 +02:00
Giuseppe Guerra
612e808702 Add !mp start force, start game even for non-ready players, check if everyone is ready in !mp start 2017-08-11 00:57:58 +02:00
Giuseppe Guerra
466004f239 Add various locks in osuToken object 2017-08-11 00:45:44 +02:00
goeo_
5f279da6cf Send the api fail info and teams too when a mp match finishes. 2017-08-10 15:53:18 -04:00
Giuseppe Guerra
aa1887e2c4 Fix match teams not being changed 2017-08-08 00:56:39 +02:00
Giuseppe Guerra
df2a9bb13d Bump version to 1.13.0 2017-08-07 23:53:21 +02:00
Giuseppe Guerra
e2149d7d61 Fix wrong variable names 2017-08-07 23:53:09 +02:00
Giuseppe Guerra
ffc84448a2 Fix non-working packet 93, allow tournament-only packets only from tourney clients 2017-08-07 23:39:13 +02:00
Giuseppe Guerra
933c92e5f2 Allow tourney clients to send messages in chat, send match info to lobby after creating it with !mp make 2017-08-07 23:35:33 +02:00
Giuseppe Guerra
3bb1029832 Add !mp team 2017-08-07 23:21:49 +02:00
Giuseppe Guerra
ce889e608a Add !mp mods 2017-08-07 22:30:44 +02:00
Giuseppe Guerra
aeecccdd13 Add !mp password and !mp randompassword 2017-08-07 22:14:44 +02:00
Giuseppe Guerra
9425043b1e Add !mp kick 2017-08-07 21:48:09 +02:00
Giuseppe Guerra
f660a20f60 Changed !mp start countdown message 2017-08-07 21:41:48 +02:00
Giuseppe Guerra
5adc7f4261 Add !mp abort, fix match not being set as in progress when starting it 2017-08-07 21:38:18 +02:00
Giuseppe Guerra
3653447761 Add !mp set 2017-08-07 20:51:16 +02:00
Giuseppe Guerra
17aab9551e Add !mp map 2017-08-06 10:09:05 +02:00
Giuseppe Guerra
87d6186993 Add !mp invite 2017-08-06 09:45:39 +02:00
Giuseppe Guerra
5975e84f52 Add !mp start 2017-08-04 01:04:26 +02:00
Giuseppe Guerra
3309f2f8fd Add !mp host and !mp clearhost 2017-08-04 00:24:12 +02:00
Giuseppe Guerra
baa8ae4cc2 Changes !mp clear to !mp close 2017-08-04 00:10:26 +02:00
Giuseppe Guerra
837df03f05 Fix typo 2017-08-04 00:09:50 +02:00
Giuseppe Guerra
c2a2d9c97b Change minimum !mp size value from 1 to 2 2017-08-03 23:56:04 +02:00
Giuseppe Guerra
fc989a2705 Fix tourney chat channels get deleted when there's nobody in the channel 2017-08-03 23:55:26 +02:00
Giuseppe Guerra
310bc1d3b3 Add !mp size 2017-08-03 23:47:34 +02:00
Giuseppe Guerra
9f647d5f9e Add !switchserver command 2017-08-02 01:36:37 +02:00
Giuseppe Guerra
1e6ee91685 Add !mp lock and !mp unlock 2017-08-02 00:39:16 +02:00
Giuseppe Guerra
86995feb34 Alert users when entering tournament matches, make impossible to join tournament matches from ui 2017-08-02 00:29:12 +02:00
Giuseppe Guerra
af554c94d5 Add !mp make and !mp join 2017-08-02 00:22:57 +02:00
Giuseppe Guerra
3373bc9581 Fix foka responding to commands even if the command is not at the beginning of the message 2017-08-02 00:02:46 +02:00
goeo_
2cf1cdf1fd Send the api some data when a multiplayer match ends 2017-07-31 17:54:50 -04:00
Giuseppe Guerra
8c3fc6842d Release locks properly 2017-07-28 22:46:29 +02:00
Giuseppe Guerra
eab8bee828 Merge branch 'master' of git.zxq.co:ripple/pep.py 2017-07-28 22:36:19 +02:00
Giuseppe Guerra
66061d5fb2 Lock client buffers while writing 2017-07-28 22:32:30 +02:00
goeo_
401dd5ecdb Fix the multiplayer password bug while not breaking anything else, especially not multiplayer as a whole. (tested code) 2017-07-23 14:37:12 -04:00
goeo_
d439490029 I should get a proper development environment 2017-07-23 12:21:38 +02:00
goeo_
f4d0a2424d .HIDE. I suck at coding
does the hide tag even work lol
2017-07-23 12:17:57 +02:00
goeo_
a177e65fcf Silence check is already done in bancho; made the ban check look better
weirdly, the original bug report said silenced people could talk using irc
2017-07-23 12:16:29 +02:00
goeo_
c14c86fe0d Fixed The Underscore Bug (i think) 2017-07-23 03:40:51 +02:00
goeo_
25df2228e3 Finally tested the code and it works now 2017-07-23 02:58:47 +02:00
goeo_
941cf81877 Parenthesis
haha coding on windows sucks because the easiest way to test the code is to push the code then pull it from my dev server
2017-07-23 02:38:37 +02:00
goeo_
76bb15f9f3 Banned/Restricted people can't use the IRC gateway. Silenced people can't send messages on it. 2017-07-23 02:35:29 +02:00
goeo_
8043d686c5 Fix all multi passwords being sent to each user in lobby 2017-07-22 22:41:42 +02:00
Nyo
cae82bd107 Delete timed out tokens 2017-07-04 23:16:10 +02:00
goeo_
2c2c85b382 Trying to fix the user metadata problem. Will this kill performance? 2017-04-16 06:41:25 -04:00
Giuseppe Guerra
a0fdc6c292 1.12.1 2017-04-13 17:22:55 +02:00
Giuseppe Guerra
487f583083 Update submodules 2017-04-13 17:22:35 +02:00
Giuseppe Guerra
530d0c3b74 Update submodules 2017-04-12 21:11:05 +02:00
Giuseppe Guerra
46ec4f3704 Merge branch 'master' of zxq.co:ripple/pep.py 2017-04-11 18:18:19 +02:00
Giuseppe Guerra
0aa0ab0475 Update submodules, moved global leaderboards to redis 2017-04-11 18:18:07 +02:00
Giuseppe Guerra
1c2a29a88e Merge branch 'master' of AiAe/pep.py into master 2017-04-10 20:02:47 +02:00
Daniel
92e57aff28 Update 'filters.txt' 2017-04-10 19:21:41 +02:00
Giuseppe Guerra
7e535d7ed5 Remove peppy->nyo filter 2017-04-08 19:21:49 +02:00
Giuseppe Guerra
0464f713f7 Merge branch 'master' of AiAe/pep.py into master 2017-04-08 19:21:04 +02:00
Daniel
66776c60e0 ¯\_(ツ)_/¯ 2017-04-08 19:11:05 +02:00
Morgan Bazalgette
4ef98b5fc0 Howl porcoddio l'indentazione 2017-02-16 22:11:15 +01:00
Morgan Bazalgette
96add06b44 Add some more FAQs as requested by AiAe 2017-02-16 22:10:03 +01:00
Nyo
31971d4a8b .HIDE. Update submodules 2017-02-03 21:46:31 +01:00
Nyo
9175f9e7f2 .BANCHO. .FIX. Fix utf-8 characters not being displayed correctly in chatlogs 2017-01-17 19:24:12 +01:00
Nyo
784c4a11f1 .BANCHO. Switch from mirrorapi to cheesegull for beatmap update requests 2017-01-16 21:24:15 +01:00
Nyo
2407ecc3bf .HIDE. Change submodule url to new git server and use HTTPS instead of SSH 2017-01-16 19:39:54 +01:00
Nyo
9880c5004d .BANCHO. .FIX. Chat mods can now write in moderated channel and access #admin channel 2017-01-16 19:37:41 +01:00
Nyo
d2f111fd7b .HIDE. Update submodules 2017-01-10 19:55:43 +01:00
Nyo
e489221e39 .HIDE. Update submodules 2017-01-06 12:56:32 +01:00
Nyo
84f1fb566c .BANCHO. Removed dashes in when tracking notes for CM 2017-01-06 12:55:50 +01:00
Nyo
fc3736eba8 .BANCHO. Remove double prefix on bancho start schiavo message 2017-01-06 12:23:45 +01:00
Nyo
768913da59 .BANCHO. Allow !last only in PM 2017-01-06 12:01:07 +01:00
Nyo
c6417c31ed ⬆️ v1.11.2 ⬆️ 2017-01-06 11:48:59 +01:00
Nyo
9055fcaf5e .BANCHO. .FIX. Fix some format errors 2016-12-28 16:15:07 +01:00
Nyo
f85640ae39 .HIDE. Update landscape config file 2016-12-28 16:12:39 +01:00
Nyo
18a7c47db6 .BANCHO. Add tornado-sentry capture decorators 2016-12-28 12:41:24 +01:00
Nyo
22ae4c332b .BANCHO. Log username changes to user notes in RAP 2016-12-28 12:16:46 +01:00
Nyo
8f156a0702 .HIDE. Update submodules 2016-12-26 10:33:39 +01:00
Nyo
62b67da9fb .HIDE. General refactoring 2016-12-26 10:33:05 +01:00
Nyo
501130721d .HIDE. Update submodules 2016-12-26 10:00:38 +01:00
Nyo
e6cdef4580 .BANCHO. Removed some schiavo logs 2016-12-26 09:59:33 +01:00
Nyo
00c544b7c7 .BANCHO. Removed some schiavo logs 2016-12-26 09:52:43 +01:00
Nyo
ebf0e1d458 .BANCHO. .FIX. Fix stop spectating not working properly if host disconnects 2016-12-21 23:26:47 +01:00
Nyo
fd23cf2b2c ⬆️ v1.11.1 ⬆️ 2016-12-21 18:20:55 +01:00
Nyo
8a8a4968a3 .BANCHO. .FIX. Fix streams and temporary chat channels not being disposed correctly 2016-12-21 18:17:29 +01:00
Nyo
2ae3c5f701 .BANCHO. Add redis notifications pubsub handler 2016-12-20 21:22:25 +01:00
Nyo
f4c099c809 .BANCHO. .FIX. Remove extra characters from version 2016-12-20 20:39:29 +01:00
Nyo
f8cc0c738c Add code health badge in README 2016-12-17 15:33:12 +01:00
Nyo
4557b08df8 Add landscape config file 2016-12-17 15:28:55 +01:00
Nyo
49f8bd8cf1 .BANCHO. .HIDE. Antiamo a kuartare i kantieri koi vekki............... 2016-12-12 22:59:58 +01:00
Nyo
7ba5db62b4 .BANCHO. Report result is now a notification rather than a FokaBot message 2016-12-12 22:57:00 +01:00
Nyo
7f534f0984 .BANCHO. .FIX. Fix hour in user report chatlog 2016-12-12 22:45:31 +01:00
Nyo
daf457fc5c .BANCHO. Add !report command 2016-12-11 23:12:06 +01:00
Nyo
b4d498c26c .BANCHO. Kick all clients when using !kick, don't kick FokaBot with !kick command 2016-12-11 11:39:01 +01:00
Nyo
44545c3bcb .BANCHO. Use streams for public chat 2016-12-11 11:07:35 +01:00
Nyo
c4a6c84cec .BANCHO. .HIDE. General refactoring 2016-12-10 19:31:12 +01:00
Nyo
8532731f19 .BANCHO. .FIX. Run safeUsername on /api/v1/isOnline 2016-12-10 19:30:38 +01:00
Nyo
b836f77446 .BANCHO. .FIX. Fix !kick command not working on irc clients 2016-12-10 19:10:00 +01:00
Nyo
e92cbe47bd ⬆️ 1.11.0 ⬆️ 2016-12-09 13:19:04 +01:00
Nyo
6ca2016f7b .BANCHO. Disabled datadog ram usage tracking 2016-12-09 11:47:00 +01:00
Nyo
2f54a56b7a Add full build script 2016-12-08 15:46:21 +01:00
Nyo
cf9e506875 .HIDE. Update submodules 2016-12-08 12:04:59 +01:00
Nyo
5c93d692ea .BANCHO. Cythonized mainHandler 2016-12-08 11:44:27 +01:00
Nyo
a8a1dfb1bc .HIDE. Update .gitignore 2016-12-08 11:44:12 +01:00
Nyo
9d562e7acd .BANCHO. Dynamic setup.py file 2016-12-08 11:43:23 +01:00
Nyo
4f4253afce .HIDE. Update README.txt 2016-12-07 22:31:28 +01:00
Nyo
04898c24ae .BANCHO. Ported packet encoder/decoder to Cython, add distutils setup file, update .gitignore, README and requirements.txt 2016-12-07 22:25:16 +01:00
Nyo
1b94936092 .BANCHO. .FIX. Fix wrong default configuration file 2016-12-07 21:15:55 +01:00
Nyo
d4591b42a3 .BANCHO. !kickall command now requires 'manage server' privilege 2016-12-07 21:15:23 +01:00
Nyo
69508f9a0e Add Google auth 2fa check at login 2016-11-30 23:33:56 +01:00
Nyo
5cf8c1bde8 Merge branch 'master' of git.zxq.co:ripple/pep.py 2016-11-30 20:08:54 +01:00
Nyo
20be60d9db Update submodules 2016-11-30 20:08:43 +01:00
Howl
61935f323c add link to github mirror 2016-11-29 17:21:24 +01:00
Nyo
cecef18d13 .HIDE. Update submodules 2016-11-20 14:17:35 +01:00
Nyo
5723c0e68f .BANCHO. Move online users count to redis 2016-11-20 14:17:05 +01:00
Nyo
525235a27e .BANCHO. Move bancho sessions to redis 2016-11-20 13:03:07 +01:00
Nyo
3bc390e3e6 .HIDE. Update submodules 2016-11-20 12:32:45 +01:00
Nyo
f6ae673401 .HIDE. Update submodules 2016-11-20 11:32:21 +01:00
Nyo
aa32e8bea6 .BANCHO. Add pubsub handlers for username changes, bans, restrictions, silences, stats update, kicks and bancho settings reload. 2016-11-20 11:31:51 +01:00
Nyo
fb00063e0f ⬆️ v1.10.0 ⬆️ 2016-11-17 20:13:36 +01:00
Nyo
e30893d66f .BANCHO. Add lets version in !system status 2016-11-17 20:11:11 +01:00
Nyo
8078596a0a .HIDE. Removed shrug version 2016-11-17 20:10:32 +01:00
Nyo
eefec1f47b .BANCHO. Save pep.py version in redis 2016-11-17 20:07:06 +01:00
Nyo
2992dc6190 .HIDE. Update submodules 2016-11-17 19:39:50 +01:00
Nyo
b6e2319e8c .HIDE. Remove random prints, fix #9 2016-11-17 19:15:14 +01:00
Nyo
a2ef03c887 .HIDE. General refactoring and documentation 2016-11-17 19:13:06 +01:00
Nyo
abad698fe3 .HIDE. avail pls 2016-11-17 15:28:07 +01:00
Nyo
030d556b9c .BANCHO. /api/v1/isOnline now supports both safe and unsafe usernames 2016-11-17 15:27:27 +01:00
Nyo
d51b304fbe .HIDE. Update submodules 2016-11-17 13:39:57 +01:00
Nyo
1ecc73e0dc .HIDE. Update submodules 2016-11-16 23:22:25 +01:00
Nyo
b1315815b2 Merge branch 'master' of git.zxq.co:ripple/pep.py 2016-11-15 20:38:58 +01:00
Nyo
38bcf3a735 .BANCHO. Add redis support, remove userID cache 2016-11-15 20:38:15 +01:00
Nyo
a6292c7374 Add redis support, remove userID cache 2016-11-15 20:36:29 +01:00
Nyo
ef940771d8 .HIDE. Update submodules 2016-11-13 19:06:47 +01:00
Nyo
b03d51abff .HIDE. Update submodules 2016-11-13 18:47:10 +01:00
Nyo
8ef02faf36 .HIDE. Update submodules 2016-11-13 12:36:10 +01:00
Nyo
d29dcd25f7 .BANCHO. Remove schiavo logs for /np in #spect_* 2016-11-13 12:35:15 +01:00
Nyo
cd75d1ad8d .BANCHO. Add bancho components RAM usage as datadog stats 2016-11-13 12:25:38 +01:00
Nyo
c7c5528588 .BANCHO. .FIX. Fix /away command, add support for /away command on IRC 2016-11-13 12:23:45 +01:00
Nyo
3b150d70cd .BANCHO. Decrease IRC polling time to 1 second 2016-11-12 22:55:43 +01:00
Nyo
d249dd593f .HIDE. Update requirements.txt 2016-11-01 09:57:43 +01:00
Nyo
78a6931805 .HIDE. Update submodules 2016-10-31 16:50:34 +01:00
Nyo
555c9cca1f .HIDE. Update requirements.txt 2016-10-31 16:40:54 +01:00
Nyo
83c514b75e .HIDE. Update submodules 2016-10-31 16:39:54 +01:00
Nyo
0e5471383e .BANCHO. Update submodules 2016-10-20 20:23:49 +02:00
Nyo
abc8e058a1 .BANCHO. .HIDE. Remove cloudflare option in config.ini 2016-10-20 20:22:23 +02:00
Nyo
0a53b31e42 .BANCHO. Enabled update command 2016-10-16 10:56:41 +02:00
Nyo
b61ac0e9b6 .BANCHO. .HIDE. Changed mirror/apiurl to mirror/api in config file 2016-10-16 10:43:04 +02:00
Nyo
a48aa73a0b .BANCHO. Add code for !update FokaBot command 2016-10-15 23:21:17 +02:00
Nyo
90dfb2c705 .BANCHO. .FIX. Don't time out tourney clients 2016-10-09 19:12:18 +02:00
Nyo
e7b7dc932a .BANCHO. Add max packets buffer size 2016-10-08 22:37:10 +02:00
Nyo
4ed5e0d14a .BANCHO. .HIDE. Update submodules 2016-10-08 22:25:27 +02:00
Nyo
0750ead5db .BANCHO. .HIDE. Removed dill from requirements list 2016-10-08 20:49:04 +02:00
Nyo
74f3ec0f4c .HIDE. Hey git pls. See last commit message 2016-10-08 20:47:19 +02:00
Nyo
fdec8620fb .BANCHO. .FIX. Match password gets set correctly on match creation 2016-10-08 20:45:53 +02:00
Nyo
8ff493f706 .BANCHO. .FIX. Make sure match data is cached before sending it 2016-10-08 20:35:09 +02:00
Nyo
2d26d36fbf .BANCHO. .FIX. Return bytes rather than None in match packets if match doesn't exist 2016-10-08 20:34:17 +02:00
Nyo
7c54df6586 .BANCHO. .FIX. Match passwords are in plain text again, fixed match invites for password protected matches 2016-10-08 20:24:16 +02:00
Nyo
2eb7fb609c .BANCHO. Cache match data for tourney client 2016-10-08 20:18:33 +02:00
Nyo
b1399aaf6e .BANCHO. Update submodules 2016-10-08 20:06:45 +02:00
Nyo
26dbdd72c1 .BANCHO. .FIX. Attempt to make getMatchData thread safe 2016-10-07 14:38:44 +02:00
Nyo
99d14b46e8 .BANCHO. .FIX. Fix typo in variable name 2016-10-07 14:14:09 +02:00
Nyo
927621cfcd .BANCHO. .FIX. Fix spectator chat 2016-10-07 14:13:42 +02:00
Nyo
847a955e2f .BANCHO. .HIDE. Meh 2016-10-07 13:44:00 +02:00
Nyo
99f76e3227 .BANCHO. .FIX. Fix None token in cantSpectateEvent 2016-10-07 13:43:47 +02:00
Nyo
ea83d3c86d .BANCHO. Use tokens in multiplayer rather than references to clients objects 2016-10-07 13:15:50 +02:00
Nyo
10e182ce55 .BANCHO. Use tokens while spectating rather than references to clients objects 2016-10-07 12:42:02 +02:00
Nyo
ca34583e7b .BANCHO. .HIDE. Update version 2016-10-07 11:06:28 +02:00
Nyo
7a7d64c209 .BANCHO. .FIX. Fix startup schiavo messages 2016-10-06 23:13:37 +02:00
Nyo
569230c16a .BANCHO. Update submodules 2016-10-06 23:07:32 +02:00
Nyo
f155b0567c .BANCHO. Add Datadog stats report 2016-10-06 23:06:59 +02:00
Nyo
05f09ad35b .BANCHO. Update submodules 2016-10-06 18:09:03 +02:00
Nyo
ead44270af .BANCHO. Update submodules 2016-10-06 17:42:26 +02:00
Nyo
820df034f4 .BANCHO. .FIX. Fix typo 2016-10-06 17:41:40 +02:00
Nyo
7347b1d455 .BANCHO. Add UserTournamentStaff privilege 2016-10-06 17:41:13 +02:00
Nyo
4babcd2643 .BANCHO. Update README and requirements 2016-10-05 23:34:42 +02:00
Nyo
142c3d35cb .BANCHO. .FIX. Fixed a bug when changing slot in multiplayer 2016-10-05 23:28:53 +02:00
Nyo
996287f871 .BANCHO. Add support for tournament client 2016-10-05 23:28:26 +02:00
Nyo
795b6f09be .BANCHO. Implemented packet streams for multiplayer 2016-10-04 23:43:02 +02:00
Nyo
afbd8e7e8c .BANCHO. Implemented packet streams for spectator and lobby 2016-10-04 22:10:07 +02:00
Nyo
cd3054c83c .HIDE. Update submodules 2016-10-02 23:23:01 +02:00
Nyo
7fcc9bca5e .BANCHO. .FIX. Fixed some missing references, code cleaning 2016-10-02 23:11:18 +02:00
Nyo
8173ff3bb6 .HIDE. Update README 2016-10-02 22:56:41 +02:00
Nyo
60e629a4fe .HIDE. Update submodules 2016-10-02 22:54:48 +02:00
Nyo
88c80a4080 Add submodules 2016-10-02 22:48:14 +02:00
Nyo
40264ceffe .BANCHO. Add streams and streamList object, add 'main' stream 2016-10-01 21:19:03 +02:00
Nyo
2213a99147 .BANCHO. .FIX. Fix negative pp value causing exception 2016-09-27 21:08:52 +02:00
Nyo
121d19aaa7 .BANCHO. Add notification when donor tag is expiring soon 2016-09-25 19:05:31 +02:00
Nyo
4b6e621a70 .BANCHO. .FIX. Fix recursive return statement 2016-09-23 17:17:30 +02:00
Nyo
712aecb602 .BANCHO. .HIDE. Update startup messages 2016-09-23 17:09:09 +02:00
Nyo
5bde0164fb .BANCHO. New MySQL helper 2016-09-23 17:08:57 +02:00
Nyo
f912f6ea82 .BANCHO. Add check for MySQL connections pool saturation 2016-09-16 18:21:34 +02:00
Nyo
6020f7cc47 .BANCHO. .FIX. Better support for username with spaces and underscores in IRC 2016-09-16 18:20:32 +02:00
Nyo
47ce794bfc .BANCHO. Add !pp command 2016-09-13 12:25:59 +02:00
Nyo
89af599e1a .BANCHO. .FIX. Fix PP overflow 2016-09-13 12:25:45 +02:00
Nyo
784973b298 Merge remote-tracking branch 'origin/master' 2016-09-13 12:03:10 +02:00
Nyo
8e4c44b857 .BANCHO. Add automatic beatmap download when spectating someone 2016-09-13 11:56:53 +02:00
Nyo
ba774bf567 .BANCHO. .HIDE. Remove debug line 2016-09-13 11:49:28 +02:00
Nyo
ea7cd9ff30 .BANCHO. .FIX. Filters are now case sensitive 2016-09-13 11:47:39 +02:00
Nyo
14348a68bb .BANCHO. Add support for locked accounts 2016-09-13 11:39:39 +02:00
Howl
fd9cde1ec6 remove (dead) getShowCountry code 2016-09-05 00:50:29 +02:00
Nyo
48925c58c0 .BANCHO. .FIX. Fix leave match right after joining 2016-09-04 17:59:12 +02:00
Nyo
17a8636de7 .BANCHO. .FIX. Fix some issues with spaced usernames on IRC 2016-09-04 17:53:12 +02:00
Nyo
f5a34d9048 .BANCHO. .FIX. Fix multiplayer free mods 2016-09-04 17:26:58 +02:00
Nyo
6aa7eb6b69 .BANCHO. .FIX. Why... 2016-09-04 16:39:59 +02:00
Nyo
19c4c32c7b .BANCHO. .FIX. Fix actions contants names 2016-09-04 16:29:36 +02:00
Nyo
7fc6d4c540 .BANCHO. Force stop spectating/quit match if user is not spectating or multiplaying 2016-09-04 16:24:00 +02:00
Nyo
255a0958ff .BANCHO. Revert ".BANCHO. Switched to tornado+gevent" 2016-09-04 16:07:10 +02:00
Nyo
31a78432bb .BANCHO. .FIX. Stop spectating only if user is spectating someone 2016-09-04 12:42:14 +02:00
Nyo
d5c87ba51c .BANCHO. Configurable IRC hostname 2016-09-04 12:36:21 +02:00
Nyo
2d91231320 .BANCHO. Add file buffers 2016-09-04 12:10:00 +02:00
Nyo
9ee2e5d7ff .BANCHO. Add userID cache 2016-09-04 12:09:53 +02:00
Nyo
cf60c167b6 .BANCHO. .FIX. Code cleaning 2016-09-02 17:45:10 +02:00
Nyo
3703618112 .BANCHO. Some code refactoring 2016-09-02 17:16:22 +02:00
Nyo
653303831b IRC Support for username with spaces
BATs with Donor have bright yellow username in chat
General performance improvements
Code cleaning
Multiplayer improvements and fixes
Fixed some spectator bugs
2016-09-02 12:41:19 +02:00
Nyo
e16e4d7493 Merge branch 'master' of git.zxq.co:ripple/pep.py 2016-08-28 17:26:02 +02:00
Nyo
a1d45a4419 .BANCHO. Add ir command, more info in system status 2016-08-28 17:25:47 +02:00
Isaac Drew
1ac48c51b5 .FIX. .BANCHO. Add scaled AR to /np with fokabot 2016-08-28 21:21:03 +08:00
Isaac Drew
27ac94a736 .FIX. .BANCHO. Add mod detection for /np when watching and playing 2016-08-28 21:20:41 +08:00
Nyo
771b6e294b .BANCHO. .HIDE. Add requirements.txt, update README 2016-08-28 11:53:35 +02:00
russelg
bd395ef30b .FIX. Actually fix meme 2016-08-24 11:10:29 +08:00
russelg
78dbd7e1f5 .FIX. Fix memes 2016-08-24 10:59:24 +08:00
Nyo
649c400883 .HIDE. version thing is bugged 2016-08-23 20:41:13 +02:00
Nyo
65b55fdcf1 .HIDE. Fix version 2016-08-23 20:39:56 +02:00
Nyo
de47c46d25 .BANCHO. Merge branch tornado-gevent into master 2016-08-23 20:35:47 +02:00
Nyo
1a31042619 .BANCHO. .FIX. Hopefully fixed headers issues with gevent 2016-08-22 22:28:18 +02:00
Nyo
7c906e48c5 .BANCHO. .FIX. Fix api/v1/onlineUsers handler 2016-08-22 15:54:01 +02:00
Nyo
2f8f8e1beb .HIDE. Update README 2016-08-22 15:31:10 +02:00
Nyo
8f79e58185 .BANCHO. /api/v1/isOnline now supports both userid and username 2016-08-21 20:32:17 +02:00
Nyo
7910291b77 .BANCHO. Switched from tornado to bottle + gevent, code cleaning 2016-08-17 16:41:05 +02:00
117 changed files with 4825 additions and 4400 deletions

6
.gitignore vendored
View File

@ -1,4 +1,10 @@
**/__pycache__ **/__pycache__
**/build
config.ini config.ini
filters.txt filters.txt
.data .data
.idea
redistest.py
*.c
*.so
.pyenv

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "common"]
path = common
url = https://github.com/osufx/ripple-python-common.git

7
.landscape.yaml Normal file
View File

@ -0,0 +1,7 @@
python-targets:
- 3
pep8:
none: true
pylint:
disable:
- cyclic-import

View File

@ -1,4 +1,8 @@
## pep.py ## pep.py [![Code Health](https://landscape.io/github/osuripple/pep.py/master/landscape.svg?style=flat)](https://landscape.io/github/osuripple/pep.py/master)
- Origin: https://git.zxq.co/ripple/pep.py
- Mirror: https://github.com/osuripple/pep.py
This is Ripple's bancho server. It handles: This is Ripple's bancho server. It handles:
- Client login - Client login
- Online users listing and statuses - Online users listing and statuses
@ -9,19 +13,30 @@ This is Ripple's bancho server. It handles:
## Requirements ## Requirements
- Python 3.5 - Python 3.5
- MySQLdb (`mysqlclient` or `mysql-python`) - Cython
- C compiler
- MySQLdb (`mysqlclient`)
- Tornado - Tornado
- Gevent
- Bcrypt - Bcrypt
- Raven
## How to set up pep.py ## How to set up pep.py
First of all, install all the dependencies First of all, initialize and update the submodules
``` ```
$ pip install mysqlclient tornado gevent bcrypt $ git submodule init && git submodule update
``` ```
then, run pep.py once to create the default config file and edit it afterwards, install the required dependencies with pip
```
$ pip install -r requirements.txt
```
then, compile all `*.pyx` files to `*.so` or `*.dll` files using `setup.py` (distutils file)
```
$ python3 setup.py build_ext --inplace
```
finally, run pep.py once to create the default config file and edit it
``` ```
$ python3 pep.py $ python3 pep.py
...
$ nano config.ini $ nano config.ini
``` ```
you can run pep.py by typing you can run pep.py by typing

1
common Submodule

@ -0,0 +1 @@
Subproject commit 6103fe96a79cd8f5cbabe24b5fac9cf2a5cacb4a

View File

@ -1,17 +0,0 @@
"""Contains user actions"""
#TODO: Uppercase
idle = 0
afk = 1
playing = 2
editing = 3
modding = 4
multiplayer = 5
watching = 6
unknown = 7
testing = 8
submitting = 9
paused = 10
lobby = 11
multiplaying= 12
osuDirect = 13
none = 14

View File

@ -1,9 +0,0 @@
"""Console colors"""
PINK = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

View File

@ -1,4 +1,3 @@
""" Contains functions used to read specific client packets from byte stream """
from constants import dataTypes from constants import dataTypes
from helpers import packetHelper from helpers import packetHelper
from constants import slotStatuses from constants import slotStatuses
@ -8,86 +7,86 @@ from constants import slotStatuses
def userActionChange(stream): def userActionChange(stream):
return packetHelper.readPacketData(stream, return packetHelper.readPacketData(stream,
[ [
["actionID", dataTypes.byte], ["actionID", dataTypes.BYTE],
["actionText", dataTypes.string], ["actionText", dataTypes.STRING],
["actionMd5", dataTypes.string], ["actionMd5", dataTypes.STRING],
["actionMods", dataTypes.uInt32], ["actionMods", dataTypes.UINT32],
["gameMode", dataTypes.byte] ["gameMode", dataTypes.BYTE],
["beatmapID", dataTypes.SINT32]
]) ])
def userStatsRequest(stream): def userStatsRequest(stream):
return packetHelper.readPacketData(stream, [["users", dataTypes.intList]]) return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
def userPanelRequest(stream): def userPanelRequest(stream):
return packetHelper.readPacketData(stream, [["users", dataTypes.intList]]) return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
""" Client chat packets """ """ Client chat packets """
def sendPublicMessage(stream): def sendPublicMessage(stream):
return packetHelper.readPacketData(stream, return packetHelper.readPacketData(stream,
[ [
["unknown", dataTypes.string], ["unknown", dataTypes.STRING],
["message", dataTypes.string], ["message", dataTypes.STRING],
["to", dataTypes.string] ["to", dataTypes.STRING]
]) ])
def sendPrivateMessage(stream): def sendPrivateMessage(stream):
return packetHelper.readPacketData(stream, return packetHelper.readPacketData(stream,
[ [
["unknown", dataTypes.string], ["unknown", dataTypes.STRING],
["message", dataTypes.string], ["message", dataTypes.STRING],
["to", dataTypes.string], ["to", dataTypes.STRING],
["unknown2", dataTypes.uInt32] ["unknown2", dataTypes.UINT32]
]) ])
def setAwayMessage(stream): def setAwayMessage(stream):
return packetHelper.readPacketData(stream, return packetHelper.readPacketData(stream,
[ [
["unknown", dataTypes.string], ["unknown", dataTypes.STRING],
["awayMessage", dataTypes.string] ["awayMessage", dataTypes.STRING]
]) ])
def channelJoin(stream): def channelJoin(stream):
return packetHelper.readPacketData(stream,[["channel", dataTypes.string]]) return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
def channelPart(stream): def channelPart(stream):
return packetHelper.readPacketData(stream,[["channel", dataTypes.string]]) return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
def addRemoveFriend(stream): def addRemoveFriend(stream):
return packetHelper.readPacketData(stream, [["friendID", dataTypes.sInt32]]) return packetHelper.readPacketData(stream, [["friendID", dataTypes.SINT32]])
""" Spectator packets """
""" SPECTATOR PACKETS """
def startSpectating(stream): def startSpectating(stream):
return packetHelper.readPacketData(stream,[["userID", dataTypes.sInt32]]) return packetHelper.readPacketData(stream, [["userID", dataTypes.SINT32]])
""" MULTIPLAYER PACKETS """ """ Multiplayer packets """
def matchSettings(stream): def matchSettings(stream):
# Data to return, will be merged later # Data to return, will be merged later
data = [] data = []
# Some settings # Some settings
struct = [ struct = [
["matchID", dataTypes.uInt16], ["matchID", dataTypes.UINT16],
["inProgress", dataTypes.byte], ["inProgress", dataTypes.BYTE],
["unknown", dataTypes.byte], ["unknown", dataTypes.BYTE],
["mods", dataTypes.uInt32], ["mods", dataTypes.UINT32],
["matchName", dataTypes.string], ["matchName", dataTypes.STRING],
["matchPassword", dataTypes.string], ["matchPassword", dataTypes.STRING],
["beatmapName", dataTypes.string], ["beatmapName", dataTypes.STRING],
["beatmapID", dataTypes.uInt32], ["beatmapID", dataTypes.UINT32],
["beatmapMD5", dataTypes.string] ["beatmapMD5", dataTypes.STRING]
] ]
# Slot statuses (not used) # Slot statuses (not used)
for i in range(0,16): for i in range(0,16):
struct.append(["slot{}Status".format(str(i)), dataTypes.byte]) struct.append(["slot{}Status".format(str(i)), dataTypes.BYTE])
# Slot statuses (not used) # Slot statuses (not used)
for i in range(0,16): for i in range(0,16):
struct.append(["slot{}Team".format(str(i)), dataTypes.byte]) struct.append(["slot{}Team".format(str(i)), dataTypes.BYTE])
# Read first part # Read first part
data.append(packetHelper.readPacketData(stream, struct)) data.append(packetHelper.readPacketData(stream, struct))
@ -100,24 +99,21 @@ def matchSettings(stream):
start += 2 start += 2
for i in range(0,16): for i in range(0,16):
s = data[0]["slot{}Status".format(str(i))] s = data[0]["slot{}Status".format(str(i))]
if s != slotStatuses.free and s != slotStatuses.locked: if s != slotStatuses.FREE and s != slotStatuses.LOCKED:
start += 4 start += 4
# Other settings # Other settings
struct = [ struct = [
["hostUserID", dataTypes.sInt32], ["hostUserID", dataTypes.SINT32],
["gameMode", dataTypes.byte], ["gameMode", dataTypes.BYTE],
["scoringType", dataTypes.byte], ["scoringType", dataTypes.BYTE],
["teamType", dataTypes.byte], ["teamType", dataTypes.BYTE],
["freeMods", dataTypes.byte], ["freeMods", dataTypes.BYTE],
] ]
# Read last part # Read last part
data.append(packetHelper.readPacketData(stream[start:], struct, False)) data.append(packetHelper.readPacketData(stream[start:], struct, False))
# Mods if freemod (not used)
#if data[1]["freeMods"] == 1:
result = {} result = {}
for i in data: for i in data:
result.update(i) result.update(i)
@ -130,19 +126,48 @@ def changeMatchSettings(stream):
return matchSettings(stream) return matchSettings(stream)
def changeSlot(stream): def changeSlot(stream):
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]]) return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
def joinMatch(stream): def joinMatch(stream):
return packetHelper.readPacketData(stream, [["matchID", dataTypes.uInt32], ["password", dataTypes.string]]) return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32], ["password", dataTypes.STRING]])
def changeMods(stream): def changeMods(stream):
return packetHelper.readPacketData(stream, [["mods", dataTypes.uInt32]]) return packetHelper.readPacketData(stream, [["mods", dataTypes.UINT32]])
def lockSlot(stream): def lockSlot(stream):
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]]) return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
def transferHost(stream): def transferHost(stream):
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]]) return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
def matchInvite(stream): def matchInvite(stream):
return packetHelper.readPacketData(stream, [["userID", dataTypes.uInt32]]) return packetHelper.readPacketData(stream, [["userID", dataTypes.UINT32]])
def matchFrames(stream):
return packetHelper.readPacketData(stream,
[
["time", dataTypes.SINT32],
["id", dataTypes.BYTE],
["count300", dataTypes.UINT16],
["count100", dataTypes.UINT16],
["count50", dataTypes.UINT16],
["countGeki", dataTypes.UINT16],
["countKatu", dataTypes.UINT16],
["countMiss", dataTypes.UINT16],
["totalScore", dataTypes.SINT32],
["maxCombo", dataTypes.UINT16],
["currentCombo", dataTypes.UINT16],
["perfect", dataTypes.BYTE],
["currentHp", dataTypes.BYTE],
["tagByte", dataTypes.BYTE],
["usingScoreV2", dataTypes.BYTE]
])
def tournamentMatchInfoRequest(stream):
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32]])
def tournamentJoinMatchChannel(stream):
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32]])
def tournamentLeaveMatchChannel(stream):
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32]])

View File

@ -1,13 +1,12 @@
"""Bancho packets data types""" """Bancho packets data types"""
#TODO: Uppercase, maybe? BYTE = 0
byte = 0 UINT16 = 1
uInt16 = 1 SINT16 = 2
sInt16 = 2 UINT32 = 3
uInt32 = 3 SINT32 = 4
sInt32 = 4 UINT64 = 5
uInt64 = 5 SINT64 = 6
sInt64 = 6 STRING = 7
string = 7 FFLOAT = 8 # because float is a keyword
ffloat = 8 # because float is a keyword BBYTES = 9
bbytes = 9 INT_LIST = 10 # TODO: Maybe there are some packets that still use uInt16 + uInt32 thing somewhere.
intList = 10 # TODO: Maybe there are some packets that still use uInt16 + uInt32 thing somewhere.

View File

@ -1,5 +1,3 @@
"""Bancho exceptions"""
# TODO: Prints in exceptions
class loginFailedException(Exception): class loginFailedException(Exception):
pass pass
@ -83,3 +81,30 @@ class haxException(Exception):
class forceUpdateException(Exception): class forceUpdateException(Exception):
pass pass
class loginLockedException(Exception):
pass
class unknownStreamException(Exception):
pass
class userTournamentException(Exception):
pass
class userAlreadyInChannelException(Exception):
pass
class userNotInChannelException(Exception):
pass
class missingReportInfoException(Exception):
pass
class invalidUserException(Exception):
pass
class wrongChannelException(Exception):
pass
class periodicLoopException(Exception):
pass

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +0,0 @@
"""Contains readable gamemodes with their codes"""
std = 0
taiko = 1
ctb = 2
mania = 3
def getGameModeForDB(gameMode):
"""
Convert a gamemode number to string for database table/column
gameMode -- gameMode int or variable (ex: gameMode.std)
return -- game mode readable string for db
"""
if gameMode == std:
return "std"
elif gameMode == taiko:
return "taiko"
elif gameMode == ctb:
return "ctb"
else:
return "mania"
def getGameModeForPrinting(gameMode):
"""
Convert a gamemode number to string for showing to a user (e.g. !last)
gameMode -- gameMode int or variable (ex: gameMode.std)
return -- game mode readable string for a human
"""
if gameMode == std:
return "osu!"
elif gameMode == taiko:
return "Taiko"
elif gameMode == ctb:
return "CatchTheBeat"
else:
return "osu!mania"

View File

@ -1,2 +1,2 @@
normal = 0 NORMAL = 0
freeMod = 1 FREE_MOD = 1

View File

@ -1,3 +1,4 @@
score = 0 SCORE = 0
accuracy = 1 ACCURACY = 1
combo = 2 COMBO = 2
SCORE_V2 = 3

View File

@ -1,4 +1,4 @@
headToHead = 0 HEAD_TO_HEAD = 0
tagCoop = 1 TAG_COOP = 1
teamVs = 2 TEAM_VS = 2
tagTeamVs = 3 TAG_TEAM_VS = 3

View File

@ -1,3 +1,3 @@
noTeam = 0 NO_TEAM = 0
blue = 1 BLUE = 1
red = 2 RED = 2

View File

@ -1,30 +0,0 @@
Nomod = 0
NoFail = 1
Easy = 2
NoVideo = 4
Hidden = 8
HardRock = 16
SuddenDeath = 32
DoubleTime = 64
Relax = 128
HalfTime = 256
Nightcore = 512
Flashlight = 1024
Autoplay = 2048
SpunOut = 4096
Relax2 = 8192
Perfect = 16384
Key4 = 32768
Key5 = 65536
Key6 = 131072
Key7 = 262144
Key8 = 524288
keyMod = 1015808
FadeIn = 1048576
Random = 2097152
LastMod = 4194304
Key9 = 16777216
Key10 = 33554432
Key1 = 67108864
Key3 = 134217728
Key2 = 268435456

View File

@ -74,7 +74,11 @@ server_channelInfoEnd = 89
client_matchChangePassword = 90 client_matchChangePassword = 90
server_matchChangePassword = 91 server_matchChangePassword = 91
server_silenceEnd = 92 server_silenceEnd = 92
client_specialMatchInfoRequest = 93
server_userSilenced = 94 server_userSilenced = 94
server_userPresenceBundle = 96 server_userPresenceBundle = 96
client_userPanelRequest = 97 client_userPanelRequest = 97
client_tournamentMatchInfoRequest = 93
server_matchAbort = 106
server_switchServer = 107
client_tournamentJoinMatchChannel = 108
client_tournamentLeaveMatchChannel = 109

View File

@ -1,21 +0,0 @@
USER_PUBLIC = 1
USER_NORMAL = 2 << 0
USER_DONOR = 2 << 1
ADMIN_ACCESS_RAP = 2 << 2
ADMIN_MANAGE_USERS = 2 << 3
ADMIN_BAN_USERS = 2 << 4
ADMIN_SILENCE_USERS = 2 << 5
ADMIN_WIPE_USERS = 2 << 6
ADMIN_MANAGE_BEATMAPS = 2 << 7
ADMIN_MANAGE_SERVERS = 2 << 8
ADMIN_MANAGE_SETTINGS = 2 << 9
ADMIN_MANAGE_BETAKEYS = 2 << 10
ADMIN_MANAGE_REPORTS = 2 << 11
ADMIN_MANAGE_DOCS = 2 << 12
ADMIN_MANAGE_BADGES = 2 << 13
ADMIN_VIEW_RAP_LOGS = 2 << 14
ADMIN_MANAGE_PRIVILEGES = 2 << 15
ADMIN_SEND_ALERTS = 2 << 16
ADMIN_CHAT_MOD = 2 << 17
ADMIN_KICK_USERS = 2 << 18
USER_PENDING_VERIFICATION = 2 << 19

View File

@ -1,69 +1,65 @@
""" Contains functions used to write specific server packets to byte streams """ """ Contains functions used to write specific server packets to byte streams """
from helpers import packetHelper from common.constants import privileges
from common.ripple import userUtils
from constants import dataTypes from constants import dataTypes
from helpers import userHelper
from objects import glob
from constants import userRanks
from constants import packetIDs from constants import packetIDs
from constants import userRanks
from helpers import packetHelper
from objects import glob
""" Login errors packets """ Login errors packets """
(userID packets derivates) """
def loginFailed(): def loginFailed():
return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
def forceUpdate(): def forceUpdate():
return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.SINT32]])
def loginBanned(): def loginBanned():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]]) packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe") packets += notification("You are banned. You can appeal after one month since your ban by sending an email to {} from the email address you've used to sign up.".format(glob.conf.extra["pep.py"]["support-email"]))
return packets
def loginLocked():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("Your account is locked. You can't log in, but your profile and scores are still visible from the website. If you want to unlock your account, send an email to {} from the email address you've used to sign up.".format(glob.conf.extra["pep.py"]["support-email"]))
return packets return packets
#return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]])
def loginError(): def loginError():
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.SINT32]])
def needSupporter(): def needSupporter():
return packetHelper.buildPacket(packetIDs.server_userID, [[-6, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[-6, dataTypes.SINT32]])
def needVerification(): def needVerification():
return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.SINT32]])
""" Login packets """ """ Login packets """
def userID(uid): def userID(uid):
return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.SINT32]])
def silenceEndTime(seconds): def silenceEndTime(seconds):
return packetHelper.buildPacket(packetIDs.server_silenceEnd, [[seconds, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_silenceEnd, [[seconds, dataTypes.UINT32]])
def protocolVersion(version = 19): def protocolVersion(version = 19):
return packetHelper.buildPacket(packetIDs.server_protocolVersion, [[version, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_protocolVersion, [[version, dataTypes.UINT32]])
def mainMenuIcon(icon): def mainMenuIcon(icon):
return packetHelper.buildPacket(packetIDs.server_mainMenuIcon, [[icon, dataTypes.string]]) return packetHelper.buildPacket(packetIDs.server_mainMenuIcon, [[icon, dataTypes.STRING]])
def userSupporterGMT(supporter, GMT): def userSupporterGMT(supporter, GMT, tournamentStaff):
result = 1 result = 1
if supporter == True: if supporter:
result += 4 result |= userRanks.SUPPORTER
if GMT == True: if GMT:
result += 2 result |= userRanks.BAT
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.uInt32]]) if tournamentStaff:
result |= userRanks.TOURNAMENT_STAFF
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.UINT32]])
def friendList(userID): def friendList(userID):
friendsData = [] friends = userUtils.getFriendList(userID)
return packetHelper.buildPacket(packetIDs.server_friendsList, [[friends, dataTypes.INT_LIST]])
# Get friend IDs from db
friends = userHelper.getFriendList(userID)
# Friends number
friendsData.append([len(friends), dataTypes.uInt16])
# Add all friend user IDs to friendsData
for i in friends:
friendsData.append([i, dataTypes.sInt32])
return packetHelper.buildPacket(packetIDs.server_friendsList, friendsData)
def onlineUsers(): def onlineUsers():
userIDs = [] userIDs = []
@ -71,27 +67,25 @@ def onlineUsers():
# Create list with all connected (and not restricted) users # Create list with all connected (and not restricted) users
for _, value in users.items(): for _, value in users.items():
if value.restricted == False: if not value.restricted:
userIDs.append(value.userID) userIDs.append(value.userID)
return packetHelper.buildPacket(packetIDs.server_userPresenceBundle, [[userIDs, dataTypes.intList]]) return packetHelper.buildPacket(packetIDs.server_userPresenceBundle, [[userIDs, dataTypes.INT_LIST]])
""" Users packets """ """ Users packets """
def userLogout(userID): def userLogout(userID):
return packetHelper.buildPacket(packetIDs.server_userLogout, [[userID, dataTypes.sInt32], [0, dataTypes.byte]]) return packetHelper.buildPacket(packetIDs.server_userLogout, [[userID, dataTypes.SINT32], [0, dataTypes.BYTE]])
def userPanel(userID, force = False): def userPanel(userID, force = False):
# Connected and restricted check # Connected and restricted check
userToken = glob.tokens.getTokenFromUserID(userID) userToken = glob.tokens.getTokenFromUserID(userID)
if userToken == None: if userToken is None or ((userToken.restricted) and not force):
return bytes()
if userToken.restricted == True and force == False:
return bytes() return bytes()
# Get user data # Get user data
username = userToken.username username = userToken.username
timezone = 24+userToken.timeOffset # TODO: Timezone timezone = 24+userToken.timeOffset
country = userToken.country country = userToken.country
gameRank = userToken.gameRank gameRank = userToken.gameRank
latitude = userToken.getLatitude() latitude = userToken.getLatitude()
@ -99,134 +93,144 @@ def userPanel(userID, force = False):
# Get username color according to rank # Get username color according to rank
# Only admins and normal users are currently supported # Only admins and normal users are currently supported
if username == "FokaBot": userRank = 0
userRank = userRanks.MOD if username == glob.BOT_NAME:
elif userHelper.isInPrivilegeGroup(userID, "community manager") == True: userRank |= userRanks.MOD
userRank = userRanks.MOD elif userUtils.isInPrivilegeGroup(userID, "developer"):
elif userHelper.isInPrivilegeGroup(userID, "developer") == True: userRank |= userRanks.ADMIN
userRank = userRanks.ADMIN elif userUtils.isInPrivilegeGroup(userID, "chat mod"):
elif userHelper.isInPrivilegeGroup(userID, "donor") == True: userRank |= userRanks.MOD
userRank = userRanks.SUPPORTER elif (userToken.privileges & privileges.USER_DONOR) > 0:
userRank |= userRanks.SUPPORTER
else: else:
userRank = userRanks.NORMAL userRank |= userRanks.NORMAL
return packetHelper.buildPacket(packetIDs.server_userPanel, return packetHelper.buildPacket(packetIDs.server_userPanel,
[ [
[userID, dataTypes.sInt32], [userID, dataTypes.SINT32],
[username, dataTypes.string], [username, dataTypes.STRING],
[timezone, dataTypes.byte], [timezone, dataTypes.BYTE],
[country, dataTypes.byte], [country, dataTypes.BYTE],
[userRank, dataTypes.byte], [userRank, dataTypes.BYTE],
[longitude, dataTypes.ffloat], [longitude, dataTypes.FFLOAT],
[latitude, dataTypes.ffloat], [latitude, dataTypes.FFLOAT],
[gameRank, dataTypes.uInt32] [gameRank, dataTypes.UINT32]
]) ])
def userStats(userID, force = False): def userStats(userID, force = False):
# Get userID's token from tokens list # Get userID's token from tokens list
userToken = glob.tokens.getTokenFromUserID(userID) userToken = glob.tokens.getTokenFromUserID(userID)
if userToken == None: if userToken is None or ((userToken.restricted or userToken.irc or userToken.tournament) and not force):
return bytes()
if (userToken.restricted == True or userToken.irc == True) and force == False:
return bytes() return bytes()
return packetHelper.buildPacket(packetIDs.server_userStats, return packetHelper.buildPacket(packetIDs.server_userStats,
[ [
[userID, dataTypes.uInt32], [userID, dataTypes.UINT32],
[userToken.actionID, dataTypes.byte], [userToken.actionID, dataTypes.BYTE],
[userToken.actionText, dataTypes.string], [userToken.actionText, dataTypes.STRING],
[userToken.actionMd5, dataTypes.string], [userToken.actionMd5, dataTypes.STRING],
[userToken.actionMods, dataTypes.sInt32], [userToken.actionMods, dataTypes.SINT32],
[userToken.gameMode, dataTypes.byte], [userToken.gameMode, dataTypes.BYTE],
[0, dataTypes.sInt32], [userToken.beatmapID, dataTypes.SINT32],
[userToken.rankedScore, dataTypes.uInt64], [userToken.rankedScore, dataTypes.UINT64],
[userToken.accuracy, dataTypes.ffloat], [userToken.accuracy, dataTypes.FFLOAT],
[userToken.playcount, dataTypes.uInt32], [userToken.playcount, dataTypes.UINT32],
[userToken.totalScore, dataTypes.uInt64], [userToken.totalScore, dataTypes.UINT64],
[userToken.gameRank, dataTypes.uInt32], [userToken.gameRank, dataTypes.UINT32],
[userToken.pp, dataTypes.uInt16] [userToken.pp if 65535 >= userToken.pp > 0 else 0, dataTypes.UINT16]
]) ])
""" Chat packets """ """ Chat packets """
def sendMessage(fro, to, message): def sendMessage(fro, to, message):
return packetHelper.buildPacket(packetIDs.server_sendMessage, [[fro, dataTypes.string], [message, dataTypes.string], [to, dataTypes.string], [userHelper.getID(fro), dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_sendMessage, [
[fro, dataTypes.STRING],
[message, dataTypes.STRING],
[to, dataTypes.STRING],
[userUtils.getID(fro), dataTypes.SINT32]
])
def channelJoinSuccess(userID, chan): def channelJoinSuccess(userID, chan):
return packetHelper.buildPacket(packetIDs.server_channelJoinSuccess, [[chan, dataTypes.string]]) return packetHelper.buildPacket(packetIDs.server_channelJoinSuccess, [[chan, dataTypes.STRING]])
def channelInfo(chan): def channelInfo(chan):
if chan not in glob.channels.channels:
return bytes()
channel = glob.channels.channels[chan] channel = glob.channels.channels[chan]
return packetHelper.buildPacket(packetIDs.server_channelInfo, [[chan, dataTypes.string], [channel.description, dataTypes.string], [channel.getConnectedUsersCount(), dataTypes.uInt16]]) return packetHelper.buildPacket(packetIDs.server_channelInfo, [
[channel.name, dataTypes.STRING],
[channel.description, dataTypes.STRING],
[len(glob.streams.streams["chat/{}".format(chan)].clients), dataTypes.UINT16]
])
def channelInfoEnd(): def channelInfoEnd():
return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.UINT32]])
def channelKicked(chan): def channelKicked(chan):
return packetHelper.buildPacket(packetIDs.server_channelKicked, [[chan, dataTypes.string]]) return packetHelper.buildPacket(packetIDs.server_channelKicked, [[chan, dataTypes.STRING]])
def userSilenced(userID): def userSilenced(userID):
return packetHelper.buildPacket(packetIDs.server_userSilenced, [[userID, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_userSilenced, [[userID, dataTypes.UINT32]])
""" Spectator packets """ """ Spectator packets """
def addSpectator(userID): def addSpectator(userID):
return packetHelper.buildPacket(packetIDs.server_spectatorJoined, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_spectatorJoined, [[userID, dataTypes.SINT32]])
def removeSpectator(userID): def removeSpectator(userID):
return packetHelper.buildPacket(packetIDs.server_spectatorLeft, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_spectatorLeft, [[userID, dataTypes.SINT32]])
def spectatorFrames(data): def spectatorFrames(data):
return packetHelper.buildPacket(packetIDs.server_spectateFrames, [[data, dataTypes.bbytes]]) return packetHelper.buildPacket(packetIDs.server_spectateFrames, [[data, dataTypes.BBYTES]])
def noSongSpectator(userID): def noSongSpectator(userID):
return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.SINT32]])
def fellowSpectatorJoined(userID): def fellowSpectatorJoined(userID):
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.SINT32]])
def fellowSpectatorLeft(userID): def fellowSpectatorLeft(userID):
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.SINT32]])
""" Multiplayer Packets """ """ Multiplayer Packets """
def createMatch(matchID): def createMatch(matchID):
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return None return bytes()
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_newMatch, match.getMatchData()) matchData = match.getMatchData(censored=True)
return packetHelper.buildPacket(packetIDs.server_newMatch, matchData)
# TODO: Add match object argument to save some CPU
def updateMatch(matchID): def updateMatch(matchID, censored = False):
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return None return bytes()
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData()) return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData(censored=censored))
def matchStart(matchID): def matchStart(matchID):
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return None return bytes()
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData()) return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData())
def disposeMatch(matchID): def disposeMatch(matchID):
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.uInt16]]) return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.UINT32]])
def matchJoinSuccess(matchID): def matchJoinSuccess(matchID):
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return None return bytes()
# Get match binary data and build packet # Get match binary data and build packet
match = glob.matches.matches[matchID] match = glob.matches.matches[matchID]
@ -237,32 +241,41 @@ def matchJoinFail():
return packetHelper.buildPacket(packetIDs.server_matchJoinFail) return packetHelper.buildPacket(packetIDs.server_matchJoinFail)
def changeMatchPassword(newPassword): def changeMatchPassword(newPassword):
return packetHelper.buildPacket(packetIDs.server_matchChangePassword, [[newPassword, dataTypes.string]]) return packetHelper.buildPacket(packetIDs.server_matchChangePassword, [[newPassword, dataTypes.STRING]])
def allPlayersLoaded(): def allPlayersLoaded():
return packetHelper.buildPacket(packetIDs.server_matchAllPlayersLoaded) return packetHelper.buildPacket(packetIDs.server_matchAllPlayersLoaded)
def playerSkipped(userID): def playerSkipped(userID):
return packetHelper.buildPacket(packetIDs.server_matchPlayerSkipped, [[userID, dataTypes.sInt32]]) return packetHelper.buildPacket(packetIDs.server_matchPlayerSkipped, [[userID, dataTypes.SINT32]])
def allPlayersSkipped(): def allPlayersSkipped():
return packetHelper.buildPacket(packetIDs.server_matchSkip) return packetHelper.buildPacket(packetIDs.server_matchSkip)
def matchFrames(slotID, data): def matchFrames(slotID, data):
return packetHelper.buildPacket(packetIDs.server_matchScoreUpdate, [[data[7:11], dataTypes.bbytes], [slotID, dataTypes.byte], [data[12:], dataTypes.bbytes]]) return packetHelper.buildPacket(packetIDs.server_matchScoreUpdate, [[data[7:11], dataTypes.BBYTES], [slotID, dataTypes.BYTE], [data[12:], dataTypes.BBYTES]])
def matchComplete(): def matchComplete():
return packetHelper.buildPacket(packetIDs.server_matchComplete) return packetHelper.buildPacket(packetIDs.server_matchComplete)
def playerFailed(slotID): def playerFailed(slotID):
return packetHelper.buildPacket(packetIDs.server_matchPlayerFailed, [[slotID, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_matchPlayerFailed, [[slotID, dataTypes.UINT32]])
def matchTransferHost(): def matchTransferHost():
return packetHelper.buildPacket(packetIDs.server_matchTransferHost) return packetHelper.buildPacket(packetIDs.server_matchTransferHost)
def matchAbort():
return packetHelper.buildPacket(packetIDs.server_matchAbort)
def switchServer(address):
return packetHelper.buildPacket(packetIDs.server_switchServer, [[address, dataTypes.STRING]])
""" Other packets """ """ Other packets """
def notification(message): def notification(message):
return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.string]]) return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.STRING]])
def banchoRestart(msUntilReconnection): def banchoRestart(msUntilReconnection):
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.uInt32]]) return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]])
def rtx(message):
return packetHelper.buildPacket(0x69, [[message, dataTypes.STRING]])

View File

@ -1,8 +1,8 @@
free = 1 FREE = 1
locked = 2 LOCKED = 2
notReady = 4 NOT_READY = 4
ready = 8 READY = 8
noMap = 16 NO_MAP = 16
playing = 32 PLAYING = 32
occupied = 124 OCCUPIED = 124
playingQuit = 128 PLAYING_QUIT = 128

View File

@ -1,8 +1,8 @@
"""Bancho user ranks"""
NORMAL = 0 NORMAL = 0
PLAYER = 1 PLAYER = 1
BAT = 2
SUPPORTER = 4 SUPPORTER = 4
MOD = 6 MOD = 6
PEPPY = 8 PEPPY = 8
ADMIN = 16 ADMIN = 16
TOURNAMENTSTAFF = 32 TOURNAMENT_STAFF = 32

View File

@ -1,19 +1,17 @@
from objects import glob from common.log import logUtils as log
from constants import serverPackets
from constants import exceptions from constants import exceptions
from helpers import logHelper as log from constants import serverPackets
from objects import glob
def handle(userToken, packetData):
# get usertoken data
userID = userToken.userID
def handle(userToken, _):
try: try:
# We don't have the beatmap, we can't spectate # We don't have the beatmap, we can't spectate
target = userToken.spectating if userToken.spectating not in glob.tokens.tokens:
targetToken = glob.tokens.getTokenFromUserID(target) raise exceptions.tokenNotFoundException()
# Send the packet to host # Send the packet to host
targetToken.enqueue(serverPackets.noSongSpectator(userID)) glob.tokens.tokens[userToken.spectating].enqueue(serverPackets.noSongSpectator(userToken.userID))
except exceptions.tokenNotFoundException: except exceptions.tokenNotFoundException:
# Stop spectating if token not found # Stop spectating if token not found
log.warning("Spectator can't spectate: token not found") log.warning("Spectator can't spectate: token not found")

View File

@ -1,10 +1,7 @@
from objects import glob from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from helpers import userHelper from objects import glob
from helpers import logHelper as log
from constants import actions
from helpers import chatHelper as chat
def handle(userToken, packetData): def handle(userToken, packetData):
# Get usertoken data # Get usertoken data
@ -12,55 +9,55 @@ def handle(userToken, packetData):
username = userToken.username username = userToken.username
# Make sure we are not banned # Make sure we are not banned
if userHelper.isBanned(userID) == True: #if userUtils.isBanned(userID):
userToken.enqueue(serverPackets.loginBanned()) # userToken.enqueue(serverPackets.loginBanned())
return # return
# Send restricted message if needed # Send restricted message if needed
if userToken.restricted == False: #if userToken.restricted:
if userHelper.isRestricted(userID) == True: # userToken.checkRestricted(True)
userToken.setRestricted()
# Change action packet # Change action packet
packetData = clientPackets.userActionChange(packetData) packetData = clientPackets.userActionChange(packetData)
# Update cached stats if our pp changedm if we've just submitted a score or we've changed gameMode # If we are not in spectate status but we're spectating someone, stop spectating
if (userToken.actionID == actions.playing or userToken.actionID == actions.multiplaying) or (userToken.pp != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]): '''
log.debug("!!!! UPDATING CACHED STATS !!!!") if userToken.spectating != 0 and userToken.actionID != actions.WATCHING and userToken.actionID != actions.IDLE and userToken.actionID != actions.AFK:
# Always update game mode, or we'll cache stats from the wrong game mode if we've changed it userToken.stopSpectating()
# If we are not in multiplayer but we are in a match, part match
if userToken.matchID != -1 and userToken.actionID != actions.MULTIPLAYING and userToken.actionID != actions.MULTIPLAYER and userToken.actionID != actions.AFK:
userToken.partMatch()
'''
# Update cached stats if our pp changed if we've just submitted a score or we've changed gameMode
#if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userUtils.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
# Update cached stats if we've changed gamemode
if userToken.gameMode != packetData["gameMode"]:
userToken.gameMode = packetData["gameMode"] userToken.gameMode = packetData["gameMode"]
userToken.updateCachedStats() userToken.updateCachedStats()
# Always update action id, text and md5 # Always update action id, text, md5 and beatmapID
userToken.actionID = packetData["actionID"] userToken.actionID = packetData["actionID"]
userToken.actionText = packetData["actionText"] userToken.actionText = packetData["actionText"]
userToken.actionMd5 = packetData["actionMd5"] userToken.actionMd5 = packetData["actionMd5"]
userToken.actionMods = packetData["actionMods"] userToken.actionMods = packetData["actionMods"]
userToken.beatmapID = packetData["beatmapID"]
# Enqueue our new user panel and stats to us and our spectators # Enqueue our new user panel and stats to us and our spectators
recipients = [userID] recipients = [userToken]
if len(userToken.spectators) > 0: if len(userToken.spectators) > 0:
recipients += userToken.spectators for i in userToken.spectators:
if i in glob.tokens.tokens:
recipients.append(glob.tokens.tokens[i])
for i in recipients: for i in recipients:
if i == userID: if i is not None:
# Save some loops
token = userToken
else:
token = glob.tokens.getTokenFromUserID(i)
if token != None:
# Force our own packet # Force our own packet
force = True if token.userID == userID else False force = True if i == userToken else False
token.enqueue(serverPackets.userPanel(userID, force)) i.enqueue(serverPackets.userPanel(userID, force))
token.enqueue(serverPackets.userStats(userID, force)) i.enqueue(serverPackets.userStats(userID, force))
# Send osu!direct alert if needed
# NOTE: Remove this when osu!direct will be fixed
if userToken.actionID == actions.osuDirect and userToken.osuDirectAlert == False:
userToken.osuDirectAlert = True
chat.sendMessage("FokaBot", userToken.username, "Sup! osu!direct works, but you'll need to update the switcher to have the Download button working. If you didn't update the switcher yet, please do!")
# Console output # Console output
log.info("{} changed action: {} [{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5)) log.info("{} changed action: {} [{}][{}][{}]".format(username, str(userToken.actionID), userToken.actionText, userToken.actionMd5, userToken.beatmapID))

View File

@ -1,7 +1,8 @@
from objects import glob from common.constants import mods
from constants import clientPackets from constants import clientPackets
from constants import matchModModes from constants import matchModModes
from constants import mods from objects import glob
def handle(userToken, packetData): def handle(userToken, packetData):
# Get token data # Get token data
@ -14,30 +15,29 @@ def handle(userToken, packetData):
matchID = userToken.matchID matchID = userToken.matchID
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
match = glob.matches.matches[matchID]
# Set slot or match mods according to modType # Set slot or match mods according to modType
if match.matchModMode == matchModModes.freeMod: with glob.matches.matches[matchID] as match:
# Freemod if match.matchModMode == matchModModes.FREE_MOD:
# Freemod
# Host can set global DT/HT
if userID == match.hostUserID:
# If host has selected DT/HT and Freemod is enabled, set DT/HT as match mod
if (packetData["mods"] & mods.DOUBLETIME) > 0:
match.changeMods(mods.DOUBLETIME)
# Nightcore
if (packetData["mods"] & mods.NIGHTCORE) > 0:
match.changeMods(match.mods + mods.NIGHTCORE)
elif (packetData["mods"] & mods.HALFTIME) > 0:
match.changeMods(mods.HALFTIME)
else:
# No DT/HT, set global mods to 0 (we are in freemod mode)
match.changeMods(0)
# Host can set global DT/HT # Set slot mods
if userID == match.hostUserID: slotID = match.getUserSlotID(userID)
# If host has selected DT/HT and Freemod is enabled, set DT/HT as match mod if slotID is not None:
if (packetData["mods"] & mods.DoubleTime) > 0: match.setSlotMods(slotID, packetData["mods"])
match.changeMatchMods(mods.DoubleTime) else:
# Nighcore # Not freemod, set match mods
if (packetData["mods"] & mods.Nightcore) > 0: match.changeMods(packetData["mods"])
match.changeMatchMods(match.mods+mods.Nightcore)
elif (packetData["mods"] & mods.HalfTime) > 0:
match.changeMatchMods(mods.HalfTime)
else:
# No DT/HT, set global mods to 0 (we are in freemod mode)
match.changeMatchMods(0)
# Set slot mods
slotID = match.getUserSlotID(userID)
if slotID != None:
match.setSlotMods(slotID, packetData["mods"])
else:
# Not freemod, set match mods
match.changeMatchMods(packetData["mods"])

View File

@ -10,8 +10,10 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Get our match with glob.matches.matches[matchID] as match:
match = glob.matches.matches[matchID] # Host check
if userToken.userID != match.hostUserID:
return
# Update match password # Update match password
match.changePassword(packetData["matchPassword"]) match.changePassword(packetData["matchPassword"])

View File

@ -1,13 +1,14 @@
from objects import glob import random
from common import generalUtils
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import matchModModes from constants import matchModModes
from helpers import consoleHelper
from constants import bcolors
import random
from constants import matchTeamTypes from constants import matchTeamTypes
from constants import matchTeams from constants import matchTeams
from constants import slotStatuses from constants import slotStatuses
from helpers import logHelper as log from objects import glob
def handle(userToken, packetData): def handle(userToken, packetData):
# Read new settings # Read new settings
@ -15,96 +16,89 @@ def handle(userToken, packetData):
# Get match ID # Get match ID
matchID = userToken.matchID matchID = userToken.matchID
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Get match object # Host check
match = glob.matches.matches[matchID] with glob.matches.matches[matchID] as match:
if userToken.userID != match.hostUserID:
return
# Some dank memes easter egg # Some dank memes easter egg
memeTitles = [ memeTitles = [
"RWC 2020", "RWC 2020",
"Fokabot is a duck", "Fokabot is a duck",
"Dank memes", "Dank memes",
"1337ms Ping", "1337ms Ping",
"Iscriviti a Xenotoze", "Iscriviti a Xenotoze",
"...e i marò?", "...e i marò?",
"Superman dies", "Superman dies",
"The brace is on fire", "The brace is on fire",
"print_foot()", "print_foot()",
"#FREEZEBARKEZ", "#FREEZEBARKEZ",
"Ripple devs are actually cats", "Ripple devs are actually cats",
"Thank Mr Shaural", "Thank Mr Shaural",
"NEVER GIVE UP", "NEVER GIVE UP",
"T I E D W I T H U N I T E D", "T I E D W I T H U N I T E D",
"HIGHEST HDHR LOBBY OF ALL TIME", "HIGHEST HDHR LOBBY OF ALL TIME",
"This is gasoline and I set myself on fire", "This is gasoline and I set myself on fire",
"Everyone is cheating apparently", "Everyone is cheating apparently",
"Kurwa mac", "Kurwa mac",
"TATOE", "TATOE",
"This is not your drama landfill.", "This is not your drama landfill.",
"I like cheese", "I like cheese",
"NYO IS NOT A CAT HE IS A DO(N)G", "NYO IS NOT A CAT HE IS A DO(N)G",
"Datingu startuato" "Datingu startuato"
] ]
# Set match name # Set match name
match.matchName = packetData["matchName"] if packetData["matchName"] != "meme" else random.choice(memeTitles) match.matchName = packetData["matchName"] if packetData["matchName"] != "meme" else random.choice(memeTitles)
# Update match settings # Update match settings
match.inProgress = packetData["inProgress"] match.inProgress = packetData["inProgress"]
match.matchPassword = packetData["matchPassword"] if packetData["matchPassword"] != "":
match.beatmapName = packetData["beatmapName"] match.matchPassword = generalUtils.stringMd5(packetData["matchPassword"])
match.beatmapID = packetData["beatmapID"] else:
match.hostUserID = packetData["hostUserID"] match.matchPassword = ""
match.gameMode = packetData["gameMode"] match.beatmapName = packetData["beatmapName"]
match.beatmapID = packetData["beatmapID"]
match.hostUserID = packetData["hostUserID"]
match.gameMode = packetData["gameMode"]
oldBeatmapMD5 = match.beatmapMD5 oldBeatmapMD5 = match.beatmapMD5
oldMods = match.mods oldMods = match.mods
oldMatchTeamType = match.matchTeamType
match.mods = packetData["mods"] match.mods = packetData["mods"]
match.beatmapMD5 = packetData["beatmapMD5"] match.beatmapMD5 = packetData["beatmapMD5"]
match.matchScoringType = packetData["scoringType"] match.matchScoringType = packetData["scoringType"]
match.matchTeamType = packetData["teamType"] match.matchTeamType = packetData["teamType"]
match.matchModMode = packetData["freeMods"] match.matchModMode = packetData["freeMods"]
# Reset ready if needed # Reset ready if needed
if oldMods != match.mods or oldBeatmapMD5 != match.beatmapMD5: if oldMods != match.mods or oldBeatmapMD5 != match.beatmapMD5:
for i in range(0,16): match.resetReady()
if match.slots[i]["status"] == slotStatuses.ready:
match.slots[i]["status"] = slotStatuses.notReady
# Reset mods if needed # Reset mods if needed
if match.matchModMode == matchModModes.normal: if match.matchModMode == matchModModes.NORMAL:
# Reset slot mods if not freeMods # Reset slot mods if not freeMods
for i in range(0,16): match.resetMods()
match.slots[i]["mods"] = 0 else:
else: # Reset match mods if freemod
# Reset match mods if freemod match.mods = 0
match.mods = 0
# Set/reset teams # Initialize teams if team type changed
if match.matchTeamType == matchTeamTypes.teamVs or match.matchTeamType == matchTeamTypes.tagTeamVs: if match.matchTeamType != oldMatchTeamType:
# Set teams match.initializeTeams()
c=0
for i in range(0,16):
if match.slots[i]["team"] == matchTeams.noTeam:
match.slots[i]["team"] = matchTeams.red if c % 2 == 0 else matchTeams.blue
c+=1
else:
# Reset teams
for i in range(0,16):
match.slots[i]["team"] = matchTeams.noTeam
# Force no freemods if tag coop # Force no freemods if tag coop
if match.matchTeamType == matchTeamTypes.tagCoop or match.matchTeamType == matchTeamTypes.tagTeamVs: if match.matchTeamType == matchTeamTypes.TAG_COOP or match.matchTeamType == matchTeamTypes.TAG_TEAM_VS:
match.matchModMode = matchModModes.normal match.matchModMode = matchModModes.NORMAL
# Send updated settings # Send updated settings
match.sendUpdate() match.sendUpdates()
# Console output # Console output
log.info("MPROOM{}: Updated room settings".format(match.matchID)) log.info("MPROOM{}: Updated room settings".format(match.matchID))
#consoleHelper.printColored("> MPROOM{}: DEBUG: Host is {}".format(match.matchID, match.hostUserID), bcolors.PINK)

View File

@ -1,18 +1,13 @@
from constants import clientPackets from constants import clientPackets
from objects import glob from objects import glob
from helpers import consoleHelper
from constants import bcolors
def handle(userToken, packetData): def handle(userToken, packetData):
# Get usertoken data # Get usertoken data
userID = userToken.userID userID = userToken.userID
username = userToken.username
# Read packet data # Read packet data
packetData = clientPackets.changeSlot(packetData) packetData = clientPackets.changeSlot(packetData)
# Get match with glob.matches.matches[userToken.matchID] as match:
match = glob.matches.matches[userToken.matchID] # Change slot
match.userChangeSlot(userID, packetData["slotID"])
# Change slot
match.userChangeSlot(userID, packetData["slotID"])

View File

@ -1,6 +1,3 @@
"""
Event called when someone parts a channel
"""
from constants import clientPackets from constants import clientPackets
from helpers import chatHelper as chat from helpers import chatHelper as chat

View File

@ -1,9 +1,8 @@
from constants import serverPackets from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets, serverPackets
from objects import glob
from events import joinMatchEvent
from constants import exceptions from constants import exceptions
from helpers import logHelper as log from objects import glob
def handle(userToken, packetData): def handle(userToken, packetData):
try: try:
@ -13,31 +12,32 @@ def handle(userToken, packetData):
# Read packet data # Read packet data
packetData = clientPackets.createMatch(packetData) packetData = clientPackets.createMatch(packetData)
# Make sure the name is valid
matchName = packetData["matchName"].strip()
if not matchName:
raise exceptions.matchCreateError()
# Create a match object # Create a match object
# TODO: Player number check # TODO: Player number check (Dirty hack below)
matchID = glob.matches.createMatch(packetData["matchName"], packetData["matchPassword"], packetData["beatmapID"], packetData["beatmapName"], packetData["beatmapMD5"], packetData["gameMode"], userID) matchID = glob.matches.createMatch(matchName, packetData["matchPassword"].strip(), packetData["beatmapID"], packetData["beatmapName"], packetData["beatmapMD5"], packetData["gameMode"], userID)
# Make sure the match has been created # Make sure the match has been created
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
raise exceptions.matchCreateError raise exceptions.matchCreateError()
# Get match object with glob.matches.matches[matchID] as match:
match = glob.matches.matches[matchID] # Join that match
userToken.joinMatch(matchID)
# Join that match # Disable slots (Dirty)
joinMatchEvent.joinMatch(userToken, matchID, packetData["matchPassword"]) for i in range(0,16):
if match.slots[i].status is not 4:
match.slots[i].status = packetData["slot{}Status".format(i)]
# Give host to match creator # Give host to match creator
match.setHost(userID) match.setHost(userID)
match.sendUpdates()
# Send match create packet to everyone in lobby match.changePassword(packetData["matchPassword"])
for i in glob.matches.usersInLobby:
# Make sure this user is still connected
token = glob.tokens.getTokenFromUserID(i)
if token != None:
token.enqueue(serverPackets.createMatch(matchID))
# Console output
log.info("MPROOM{}: Room created!".format(matchID))
except exceptions.matchCreateError: except exceptions.matchCreateError:
log.error("Error while creating match!") log.error("Error while creating match!")
userToken.enqueue(serverPackets.matchJoinFail())

View File

@ -1,11 +1,12 @@
from helpers import userHelper from common.log import logUtils as log
from common.ripple import userUtils
from constants import clientPackets from constants import clientPackets
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
# Friend add packet # Friend add packet
packetData = clientPackets.addRemoveFriend(packetData) packetData = clientPackets.addRemoveFriend(packetData)
userHelper.addFriend(userToken.userID, packetData["friendID"]) userUtils.addFriend(userToken.userID, packetData["friendID"])
# Console output # Console output
log.info("{} have added {} to their friends".format(userToken.username, str(packetData["friendID"]))) log.info("{} have added {} to their friends".format(userToken.username, str(packetData["friendID"])))

View File

@ -1,11 +1,12 @@
from helpers import userHelper from common.log import logUtils as log
from common.ripple import userUtils
from constants import clientPackets from constants import clientPackets
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
# Friend remove packet # Friend remove packet
packetData = clientPackets.addRemoveFriend(packetData) packetData = clientPackets.addRemoveFriend(packetData)
userHelper.removeFriend(userToken.userID, packetData["friendID"]) userUtils.removeFriend(userToken.userID, packetData["friendID"])
# Console output # Console output
log.info("{} have removed {} from their friends".format(userToken.username, str(packetData["friendID"]))) log.info("{} have removed {} from their friends".format(userToken.username, str(packetData["friendID"])))

View File

@ -1,14 +1,14 @@
from common.log import logUtils as log
from constants import serverPackets from constants import serverPackets
from objects import glob from objects import glob
from helpers import logHelper as log
def handle(userToken, _): def handle(userToken, _):
# Get userToken data # Get userToken data
username = userToken.username username = userToken.username
userID = userToken.userID
# Add user to users in lobby # Add user to users in lobby
glob.matches.lobbyUserJoin(userID) userToken.joinStream("lobby")
# Send matches data # Send matches data
for key, _ in glob.matches.matches.items(): for key, _ in glob.matches.matches.items():

View File

@ -1,57 +1,33 @@
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import exceptions
from constants import serverPackets from constants import serverPackets
from objects import glob from objects import glob
from constants import exceptions
from helpers import logHelper as log
from helpers import chatHelper as chat
def handle(userToken, packetData): def handle(userToken, packetData):
# read packet data # read packet data
packetData = clientPackets.joinMatch(packetData) packetData = clientPackets.joinMatch(packetData)
matchID = packetData["matchID"]
password = packetData["password"]
# Get match from ID # Get match from ID
joinMatch(userToken, packetData["matchID"], packetData["password"])
def joinMatch(userToken, matchID, password):
try: try:
# TODO: leave other matches
# TODO: Stop spectating
# get usertoken data
userID = userToken.userID
# Make sure the match exists # Make sure the match exists
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
raise exceptions.matchNotFoundException return
# Match exists, get object # Hash password if needed
match = glob.matches.matches[matchID] # if password != "":
# password = generalUtils.stringMd5(password)
# Check password # Check password
# TODO: Admins can enter every match with glob.matches.matches[matchID] as match:
if match.matchPassword != "": if match.matchPassword != "" and match.matchPassword != password:
if match.matchPassword != password: raise exceptions.matchWrongPasswordException()
raise exceptions.matchWrongPasswordException
# Password is correct, join match # Password is correct, join match
result = match.userJoin(userID) userToken.joinMatch(matchID)
# Check if we've joined the match successfully
if result == False:
raise exceptions.matchJoinErrorException
# Match joined, set matchID for usertoken
userToken.joinMatch(matchID)
# Send packets
userToken.enqueue(serverPackets.matchJoinSuccess(matchID))
chat.joinChannel(token=userToken, channel="#multi_{}".format(matchID))
except exceptions.matchNotFoundException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but it doesn't exist".format(userToken.username))
except exceptions.matchWrongPasswordException: except exceptions.matchWrongPasswordException:
userToken.enqueue(serverPackets.matchJoinFail()) userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username)) log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username))
except exceptions.matchJoinErrorException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but an error has occured".format(userToken.username))

View File

@ -1,23 +1,21 @@
from helpers import userHelper
from constants import serverPackets
from constants import exceptions
from objects import glob
from helpers import consoleHelper
from constants import bcolors
from helpers import locationHelper
from helpers import countryHelper
import time
from helpers import generalFunctions
import sys import sys
import time
import traceback import traceback
from helpers import requestHelper
from helpers import discordBotHelper from common.constants import privileges
from helpers import logHelper as log from common.log import logUtils as log
from common.ripple import userUtils
from constants import exceptions
from constants import serverPackets
from helpers import chatHelper as chat from helpers import chatHelper as chat
from constants import privileges from helpers import countryHelper
from helpers import locationHelper
from objects import glob
def handle(tornadoRequest): def handle(tornadoRequest):
# Data to return # Data to return
responseToken = None
responseTokenString = "ayy" responseTokenString = "ayy"
responseData = bytes() responseData = bytes()
@ -32,12 +30,9 @@ def handle(tornadoRequest):
# 2:-3 thing is because requestData has some escape stuff that we don't need # 2:-3 thing is because requestData has some escape stuff that we don't need
loginData = str(tornadoRequest.request.body)[2:-3].split("\\n") loginData = str(tornadoRequest.request.body)[2:-3].split("\\n")
try: try:
# If true, print error to console
err = False
# Make sure loginData is valid # Make sure loginData is valid
if len(loginData) < 3: if len(loginData) < 3:
raise exceptions.haxException() raise exceptions.invalidArgumentsException()
# Get HWID, MAC address and more # Get HWID, MAC address and more
# Structure (new line = "|", already split) # Structure (new line = "|", already split)
@ -49,29 +44,30 @@ def handle(tornadoRequest):
splitData = loginData[2].split("|") splitData = loginData[2].split("|")
osuVersion = splitData[0] osuVersion = splitData[0]
timeOffset = int(splitData[1]) timeOffset = int(splitData[1])
print(str(timeOffset))
clientData = splitData[3].split(":")[:5] clientData = splitData[3].split(":")[:5]
if len(clientData) < 4: if len(clientData) < 4:
raise exceptions.forceUpdateException() raise exceptions.forceUpdateException()
# Try to get the ID from username # Try to get the ID from username
username = str(loginData[0]) username = str(loginData[0])
userID = userHelper.getID(username) userID = userUtils.getID(username)
if userID == False: if not userID:
# Invalid username # Invalid username
raise exceptions.loginFailedException() raise exceptions.loginFailedException()
if userHelper.checkLogin(userID, loginData[1]) == False: if not userUtils.checkLogin(userID, loginData[1]):
# Invalid password # Invalid password
raise exceptions.loginFailedException() raise exceptions.loginFailedException()
# Make sure we are not banned # Make sure we are not banned or locked
priv = userHelper.getPrivileges(userID) priv = userUtils.getPrivileges(userID)
if userHelper.isBanned(userID) == True and priv & privileges.USER_PENDING_VERIFICATION == 0: if userUtils.isBanned(userID) and priv & privileges.USER_PENDING_VERIFICATION == 0:
raise exceptions.loginBannedException() raise exceptions.loginBannedException()
if userUtils.isLocked(userID) and priv & privileges.USER_PENDING_VERIFICATION == 0:
raise exceptions.loginLockedException()
# 2FA check # 2FA check
if userHelper.check2FA(userID, requestIP) == True: if userUtils.check2FA(userID, requestIP):
log.warning("Need 2FA check for user {}".format(loginData[0])) log.warning("Need 2FA check for user {}".format(loginData[0]))
raise exceptions.need2FAException() raise exceptions.need2FAException()
@ -79,8 +75,8 @@ def handle(tornadoRequest):
# Verify this user (if pending activation) # Verify this user (if pending activation)
firstLogin = False firstLogin = False
if priv & privileges.USER_PENDING_VERIFICATION > 0 or userHelper.hasVerifiedHardware(userID) == False: if priv & privileges.USER_PENDING_VERIFICATION > 0 or not userUtils.hasVerifiedHardware(userID):
if userHelper.verifyUser(userID, clientData) == True: if userUtils.verifyUser(userID, clientData):
# Valid account # Valid account
log.info("Account {} verified successfully!".format(userID)) log.info("Account {} verified successfully!".format(userID))
glob.verifiedCache[str(userID)] = 1 glob.verifiedCache[str(userID)] = 1
@ -93,27 +89,41 @@ def handle(tornadoRequest):
# Save HWID in db for multiaccount detection # Save HWID in db for multiaccount detection
hwAllowed = userHelper.logHardware(userID, clientData, firstLogin) hwAllowed = userUtils.logHardware(userID, clientData, firstLogin)
# This is false only if HWID is empty # This is false only if HWID is empty
# if HWID is banned, we get restricted so there's no # if HWID is banned, we get restricted so there's no
# need to deny bancho access # need to deny bancho access
if hwAllowed == False: if not hwAllowed:
raise exceptions.haxException() raise exceptions.haxException()
# Log user IP # Log user IP
userHelper.logIP(userID, requestIP) userUtils.logIP(userID, requestIP)
# Delete old tokens for that user and generate a new one # Delete old tokens for that user and generate a new one
glob.tokens.deleteOldTokens(userID) isTournament = "tourney" in osuVersion
responseToken = glob.tokens.addToken(userID, requestIP, timeOffset=timeOffset) if not isTournament:
glob.tokens.deleteOldTokens(userID)
responseToken = glob.tokens.addToken(userID, requestIP, timeOffset=timeOffset, tournament=isTournament)
responseTokenString = responseToken.token responseTokenString = responseToken.token
# Check restricted mode (and eventually send message) # Check restricted mode (and eventually send message)
responseToken.checkRestricted() responseToken.checkRestricted()
# Send message if donor expires soon
if responseToken.privileges & privileges.USER_DONOR > 0:
expireDate = userUtils.getDonorExpire(responseToken.userID)
if expireDate-int(time.time()) <= 86400*3:
expireDays = round((expireDate-int(time.time()))/86400)
expireIn = "{} days".format(expireDays) if expireDays > 1 else "less than 24 hours"
responseToken.enqueue(serverPackets.notification("Your donor tag expires in {}! When your donor tag expires, you won't have any of the donor privileges, like yellow username, custom badge and discord custom role and username color! If you wish to keep supporting Ripple and you don't want to lose your donor privileges, you can donate again by clicking on 'Support us' on Ripple's website.".format(expireIn)))
# Deprecate telegram 2fa and send alert
if userUtils.deprecateTelegram2Fa(userID):
responseToken.enqueue(serverPackets.notification("As stated on our blog, Telegram 2FA has been deprecated on 29th June 2018. Telegram 2FA has just been disabled from your account. If you want to keep your account secure with 2FA, please enable TOTP-based 2FA from our website https://ripple.moe. Thank you for your patience."))
# Set silence end UNIX time in token # Set silence end UNIX time in token
responseToken.silenceEndTime = userHelper.getSilenceEnd(userID) responseToken.silenceEndTime = userUtils.getSilenceEnd(userID)
# Get only silence remaining seconds # Get only silence remaining seconds
silenceSeconds = responseToken.getSilenceSecondsLeft() silenceSeconds = responseToken.getSilenceSecondsLeft()
@ -121,11 +131,14 @@ def handle(tornadoRequest):
# Get supporter/GMT # Get supporter/GMT
userGMT = False userGMT = False
userSupporter = True userSupporter = True
if responseToken.admin == True: userTournament = False
if responseToken.admin:
userGMT = True userGMT = True
if responseToken.privileges & privileges.USER_TOURNAMENT_STAFF > 0:
userTournament = True
# Server restarting check # Server restarting check
if glob.restarting == True: if glob.restarting:
raise exceptions.banchoRestartingException() raise exceptions.banchoRestartingException()
# Send login notification before maintenance message # Send login notification before maintenance message
@ -133,8 +146,8 @@ def handle(tornadoRequest):
responseToken.enqueue(serverPackets.notification(glob.banchoConf.config["loginNotification"])) responseToken.enqueue(serverPackets.notification(glob.banchoConf.config["loginNotification"]))
# Maintenance check # Maintenance check
if glob.banchoConf.config["banchoMaintenance"] == True: if glob.banchoConf.config["banchoMaintenance"]:
if userGMT == False: if not userGMT:
# We are not mod/admin, delete token, send notification and logout # We are not mod/admin, delete token, send notification and logout
glob.tokens.deleteToken(responseTokenString) glob.tokens.deleteToken(responseTokenString)
raise exceptions.banchoMaintenanceException() raise exceptions.banchoMaintenanceException()
@ -146,7 +159,7 @@ def handle(tornadoRequest):
responseToken.enqueue(serverPackets.silenceEndTime(silenceSeconds)) responseToken.enqueue(serverPackets.silenceEndTime(silenceSeconds))
responseToken.enqueue(serverPackets.userID(userID)) responseToken.enqueue(serverPackets.userID(userID))
responseToken.enqueue(serverPackets.protocolVersion()) responseToken.enqueue(serverPackets.protocolVersion())
responseToken.enqueue(serverPackets.userSupporterGMT(userSupporter, userGMT)) responseToken.enqueue(serverPackets.userSupporterGMT(userSupporter, userGMT, userTournament))
responseToken.enqueue(serverPackets.userPanel(userID, True)) responseToken.enqueue(serverPackets.userPanel(userID, True))
responseToken.enqueue(serverPackets.userStats(userID, True)) responseToken.enqueue(serverPackets.userStats(userID, True))
@ -158,12 +171,12 @@ def handle(tornadoRequest):
chat.joinChannel(token=responseToken, channel="#announce") chat.joinChannel(token=responseToken, channel="#announce")
# Join admin channel if we are an admin # Join admin channel if we are an admin
if responseToken.admin == True: if responseToken.admin:
chat.joinChannel(token=responseToken, channel="#admin") chat.joinChannel(token=responseToken, channel="#admin")
# Output channels info # Output channels info
for key, value in glob.channels.channels.items(): for key, value in glob.channels.channels.items():
if value.publicRead == True and value.hidden == False: if value.publicRead and not value.hidden:
responseToken.enqueue(serverPackets.channelInfo(key)) responseToken.enqueue(serverPackets.channelInfo(key))
# Send friends list # Send friends list
@ -173,33 +186,37 @@ def handle(tornadoRequest):
if glob.banchoConf.config["menuIcon"] != "": if glob.banchoConf.config["menuIcon"] != "":
responseToken.enqueue(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"])) responseToken.enqueue(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
# Send online users IDs array # Send online users' panels
responseToken.enqueue(serverPackets.onlineUsers()) with glob.tokens:
for _, token in glob.tokens.tokens.items():
if not token.restricted:
responseToken.enqueue(serverPackets.userPanel(token.userID))
# Get location and country from ip.zxq.co or database # Get location and country from ip.zxq.co or database
if glob.localize == True: if glob.localize:
# Get location and country from IP # Get location and country from IP
location = locationHelper.getLocation(requestIP) latitude, longitude = locationHelper.getLocation(requestIP)
countryLetters = locationHelper.getCountry(requestIP) countryLetters = locationHelper.getCountry(requestIP)
country = countryHelper.getCountryID(countryLetters) country = countryHelper.getCountryID(countryLetters)
else: else:
# Set location to 0,0 and get country from db # Set location to 0,0 and get country from db
log.warning("Location skipped") log.warning("Location skipped")
location = [0,0] latitude = 0
longitude = 0
countryLetters = "XX" countryLetters = "XX"
country = countryHelper.getCountryID(userHelper.getCountry(userID)) country = countryHelper.getCountryID(userUtils.getCountry(userID))
# Set location and country # Set location and country
responseToken.setLocation(location) responseToken.setLocation(latitude, longitude)
responseToken.setCountry(country) responseToken.country = country
# Set country in db if user has no country (first bancho login) # Set country in db if user has no country (first bancho login)
if userHelper.getCountry(userID) == "XX": if userUtils.getCountry(userID) == "XX":
userHelper.setCountry(userID, countryLetters) userUtils.setCountry(userID, countryLetters)
# Send to everyone our userpanel if we are not restricted # Send to everyone our userpanel if we are not restricted or tournament
if responseToken.restricted == False: if not responseToken.restricted:
glob.tokens.enqueueAll(serverPackets.userPanel(userID)) glob.streams.broadcast("main", serverPackets.userPanel(userID))
# Set reponse data to right value and reset our queue # Set reponse data to right value and reset our queue
responseData = responseToken.queue responseData = responseToken.queue
@ -207,21 +224,23 @@ def handle(tornadoRequest):
except exceptions.loginFailedException: except exceptions.loginFailedException:
# Login failed error packet # Login failed error packet
# (we don't use enqueue because we don't have a token since login has failed) # (we don't use enqueue because we don't have a token since login has failed)
err = True
responseData += serverPackets.loginFailed() responseData += serverPackets.loginFailed()
except exceptions.haxException: except exceptions.invalidArgumentsException:
# Invalid POST data # Invalid POST data
# (we don't use enqueue because we don't have a token since login has failed) # (we don't use enqueue because we don't have a token since login has failed)
err = True
responseData += serverPackets.loginFailed() responseData += serverPackets.loginFailed()
responseData += serverPackets.notification("I see what you're doing...") responseData += serverPackets.notification("I see what you're doing...")
except exceptions.loginBannedException: except exceptions.loginBannedException:
# Login banned error packet # Login banned error packet
err = True
responseData += serverPackets.loginBanned() responseData += serverPackets.loginBanned()
except exceptions.loginLockedException:
# Login banned error packet
responseData += serverPackets.loginLocked()
except exceptions.banchoMaintenanceException: except exceptions.banchoMaintenanceException:
# Bancho is in maintenance mode # Bancho is in maintenance mode
responseData = responseToken.queue responseData = bytes()
if responseToken is not None:
responseData = responseToken.queue
responseData += serverPackets.notification("Our bancho server is in maintenance mode. Please try to login again later.") responseData += serverPackets.notification("Our bancho server is in maintenance mode. Please try to login again later.")
responseData += serverPackets.loginFailed() responseData += serverPackets.loginFailed()
except exceptions.banchoRestartingException: except exceptions.banchoRestartingException:
@ -234,18 +253,14 @@ def handle(tornadoRequest):
except exceptions.haxException: except exceptions.haxException:
# Using oldoldold client, we don't have client data. Force update. # Using oldoldold client, we don't have client data. Force update.
# (we don't use enqueue because we don't have a token since login has failed) # (we don't use enqueue because we don't have a token since login has failed)
err = True
responseData += serverPackets.forceUpdate() responseData += serverPackets.forceUpdate()
responseData += serverPackets.notification("Hory shitto, your client is TOO old! Nice preistoria! Please turn off the switcher and update it.") responseData += serverPackets.notification("Hory shitto, your client is TOO old! Nice prehistory! Please turn update it from the settings!")
except: except:
log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc())) log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
finally: finally:
# Console and discord log # Console and discord log
if len(loginData) < 3: if len(loginData) < 3:
msg = "Invalid bancho login request from **{}** (insufficient POST data)".format(requestIP) log.info("Invalid bancho login request from **{}** (insufficient POST data)".format(requestIP), "bunker")
else:
msg = "Bancho login request from **{}** for user **{}** ({})".format(requestIP, loginData[0], "failed" if err == True else "success")
log.info(msg, "bunker")
# Return token string and data # Return token string and data
return (responseTokenString, responseData) return responseTokenString, responseData

View File

@ -1,12 +1,13 @@
from objects import glob
from helpers import consoleHelper
from constants import bcolors
from constants import serverPackets
import time import time
from helpers import logHelper as log import json
from helpers import chatHelper as chat
def handle(userToken, _=None): from common.log import logUtils as log
from constants import serverPackets
from helpers import chatHelper as chat
from objects import glob
def handle(userToken, _=None, deleteToken=True):
# get usertoken data # get usertoken data
userID = userToken.userID userID = userToken.userID
username = userToken.username username = userToken.username
@ -16,31 +17,41 @@ def handle(userToken, _=None):
# the old logout packet will still be in the queue and will be sent to # the old logout packet will still be in the queue and will be sent to
# the server, so we accept logout packets sent at least 5 seconds after login # the server, so we accept logout packets sent at least 5 seconds after login
# if the user logs out before 5 seconds, he will be disconnected later with timeout check # if the user logs out before 5 seconds, he will be disconnected later with timeout check
if int(time.time()-userToken.loginTime) >= 5 or userToken.irc == True: if int(time.time() - userToken.loginTime) >= 5 or userToken.irc:
# Stop spectating if needed # Stop spectating
# TODO: Call stopSpectatingEvent!!!!!!!!! userToken.stopSpectating()
if userToken.spectating != 0:
# The user was spectating someone
spectatorHostToken = glob.tokens.getTokenFromUserID(userToken.spectating)
if spectatorHostToken != None:
# The host is still online, send removeSpectator to him
spectatorHostToken.enqueue(serverPackets.removeSpectator(userID))
# Part matches
userToken.leaveMatch()
# Part all joined channels # Part all joined channels
for i in userToken.joinedChannels: for i in userToken.joinedChannels:
chat.partChannel(token=userToken, channel=i) chat.partChannel(token=userToken, channel=i)
# TODO: Lobby left if joined # Leave all joined streams
userToken.leaveAllStreams()
# Enqueue our disconnection to everyone else # Enqueue our disconnection to everyone else
glob.tokens.enqueueAll(serverPackets.userLogout(userID)) glob.streams.broadcast("main", serverPackets.userLogout(userID))
# Disconnect from IRC if needed # Disconnect from IRC if needed
if userToken.irc == True and glob.irc == True: if userToken.irc and glob.irc:
glob.ircServer.forceDisconnection(userToken.username) glob.ircServer.forceDisconnection(userToken.username)
# Delete token # Delete token
glob.tokens.deleteToken(requestToken) if deleteToken:
glob.tokens.deleteToken(requestToken)
else:
userToken.kicked = True
# Change username if needed
newUsername = glob.redis.get("ripple:change_username_pending:{}".format(userID))
if newUsername is not None:
log.debug("Sending username change request for user {}".format(userID))
glob.redis.publish("peppy:change_username", json.dumps({
"userID": userID,
"newUsername": newUsername.decode("utf-8")
}))
# Console output # Console output
log.info("{} has been disconnected.".format(username)) log.info("{} has been disconnected. (logout)".format(username))

View File

@ -1,6 +1,6 @@
from objects import glob from objects import glob
def handle(userToken, packetData, has): def handle(userToken, _, has):
# Get usertoken data # Get usertoken data
userID = userToken.userID userID = userToken.userID
@ -15,8 +15,6 @@ def handle(userToken, packetData, has):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object
match = glob.matches.matches[matchID]
# Set has beatmap/no beatmap # Set has beatmap/no beatmap
match.userHasBeatmap(userID, has) with glob.matches.matches[matchID] as match:
match.userHasBeatmap(userID, has)

View File

@ -15,8 +15,6 @@ def handle(userToken, _):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Get match object
match = glob.matches.matches[matchID]
# Change team # Change team
match.changeTeam(userID) with glob.matches.matches[matchID] as match:
match.changeTeam(userID)

View File

@ -1,6 +1,6 @@
from objects import glob from objects import glob
def handle(userToken, packetData): def handle(userToken, _):
# Get usertoken data # Get usertoken data
userID = userToken.userID userID = userToken.userID
@ -15,8 +15,6 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object
match = glob.matches.matches[matchID]
# Set our match complete # Set our match complete
match.playerCompleted(userID) with glob.matches.matches[matchID] as match:
match.playerCompleted(userID)

View File

@ -15,8 +15,6 @@ def handle(userToken, _):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Match exists, get object
match = glob.matches.matches[matchID]
# Fail user # Fail user
match.playerFailed(userID) with glob.matches.matches[matchID] as match:
match.playerFailed(userID)

View File

@ -1,7 +1,5 @@
from objects import glob from objects import glob
from constants import slotStatuses from constants import serverPackets, clientPackets
from constants import serverPackets
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
# Get usertoken data # Get usertoken data
@ -18,15 +16,16 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object # Parse the data
match = glob.matches.matches[matchID] data = clientPackets.matchFrames(packetData)
# Change slot id in packetData with glob.matches.matches[matchID] as match:
slotID = match.getUserSlotID(userID) # Change slot id in packetData
slotID = match.getUserSlotID(userID)
# Enqueue frames to who's playing # Update the score
for i in range(0,16): match.updateScore(slotID, data["totalScore"])
if match.slots[i]["userID"] > -1 and match.slots[i]["status"] == slotStatuses.playing: match.updateHP(slotID, data["currentHp"])
token = glob.tokens.getTokenFromUserID(match.slots[i]["userID"])
if token != None: # Enqueue frames to who's playing
token.enqueue(serverPackets.matchFrames(slotID, packetData)) glob.streams.broadcast(match.playingStreamName, serverPackets.matchFrames(slotID, packetData))

View File

@ -1,3 +1,4 @@
from events import matchBeatmapEvent from events import matchBeatmapEvent
def handle(userToken, packetData): def handle(userToken, packetData):
matchBeatmapEvent.handle(userToken, packetData, True) matchBeatmapEvent.handle(userToken, packetData, True)

View File

@ -17,8 +17,6 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Get match object
match = glob.matches.matches[matchID]
# Send invite # Send invite
match.invite(userID, packetData["userID"]) with glob.matches.matches[matchID] as match:
match.invite(userID, packetData["userID"])

View File

@ -12,12 +12,16 @@ def handle(userToken, packetData):
matchID = userToken.matchID matchID = userToken.matchID
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
match = glob.matches.matches[matchID]
# Make sure we aren't locking our slot with glob.matches.matches[matchID] as match:
ourSlot = match.getUserSlotID(userID) # Host check
if packetData["slotID"] == ourSlot: if userID != match.hostUserID:
return return
# Lock/Unlock slot # Make sure we aren't locking our slot
match.toggleSlotLock(packetData["slotID"]) ourSlot = match.getUserSlotID(userID)
if packetData["slotID"] == ourSlot:
return
# Lock/Unlock slot
match.toggleSlotLocked(packetData["slotID"])

View File

@ -1,3 +1,4 @@
from events import matchBeatmapEvent from events import matchBeatmapEvent
def handle(userToken, packetData): def handle(userToken, packetData):
matchBeatmapEvent.handle(userToken, packetData, False) matchBeatmapEvent.handle(userToken, packetData, False)

View File

@ -1,6 +1,6 @@
from objects import glob from objects import glob
def handle(userToken, packetData): def handle(userToken, _):
# Get userToken data # Get userToken data
userID = userToken.userID userID = userToken.userID
@ -15,8 +15,6 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object
match = glob.matches.matches[matchID]
# Set our load status # Set our load status
match.playerLoaded(userID) with glob.matches.matches[matchID] as match:
match.playerLoaded(userID)

View File

@ -8,9 +8,14 @@ def handle(userToken, _):
matchID = userToken.matchID matchID = userToken.matchID
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
match = glob.matches.matches[matchID]
# Get our slotID and change ready status with glob.matches.matches[matchID] as match:
slotID = match.getUserSlotID(userID) # Get our slotID and change ready status
if slotID != None: slotID = match.getUserSlotID(userID)
match.toggleSlotReady(slotID) if slotID is not None:
match.toggleSlotReady(slotID)
# If this is a tournament match, we should send the current status of ready
# players.
if match.isTourney:
match.sendReadyStatus()

View File

@ -1,6 +1,6 @@
from objects import glob from objects import glob
def handle(userToken, packetData): def handle(userToken, _):
# Get userToken data # Get userToken data
userID = userToken.userID userID = userToken.userID
@ -15,8 +15,6 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object
match = glob.matches.matches[matchID]
# Skip # Skip
match.playerSkip(userID) with glob.matches.matches[matchID] as match:
match.playerSkip(userID)

View File

@ -1,9 +1,6 @@
from objects import glob from objects import glob
from constants import slotStatuses
from constants import serverPackets
def handle(userToken, _): def handle(userToken, _):
# TODO: Host check
# Get match ID and match object # Get match ID and match object
matchID = userToken.matchID matchID = userToken.matchID
@ -16,32 +13,9 @@ def handle(userToken, _):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# The match exists, get object with glob.matches.matches[matchID] as match:
match = glob.matches.matches[matchID] # Host check
if userToken.userID != match.hostUserID:
return
force = False # TODO: Force thing match.start()
# Make sure we have enough players
if (match.countUsers() < 2 or not match.checkTeams()) and not force:
return
# Change inProgress value
match.inProgress = True
# Set playing to ready players and set load, skip and complete to False
for i in range(0,16):
if (match.slots[i]["status"] & slotStatuses.ready) > 0:
match.slots[i]["status"] = slotStatuses.playing
match.slots[i]["loaded"] = False
match.slots[i]["skip"] = False
match.slots[i]["complete"] = False
# Send match start packet
for i in range(0,16):
if (match.slots[i]["status"] & slotStatuses.playing) > 0 and match.slots[i]["userID"] != -1:
token = glob.tokens.getTokenFromUserID(match.slots[i]["userID"])
if token != None:
token.enqueue(serverPackets.matchStart(matchID))
# Send updates
match.sendUpdate()

View File

@ -16,8 +16,10 @@ def handle(userToken, packetData):
if matchID not in glob.matches.matches: if matchID not in glob.matches.matches:
return return
# Match exists, get object # Host check
match = glob.matches.matches[matchID] with glob.matches.matches[matchID] as match:
if userToken.userID != match.hostUserID:
return
# Transfer host # Transfer host
match.transferHost(packetData["slotID"]) match.transferHost(packetData["slotID"])

View File

@ -1,17 +1,15 @@
from objects import glob from common.log import logUtils as log
from events import channelPartEvent
from helpers import logHelper as log
from helpers import chatHelper as chat from helpers import chatHelper as chat
def handle(userToken, _): def handle(userToken, _):
# Get usertoken data # Get usertoken data
userID = userToken.userID
username = userToken.username username = userToken.username
# Remove user from users in lobby # Remove user from users in lobby
glob.matches.lobbyUserPart(userID) userToken.leaveStream("lobby")
# Part lobby channel # Part lobby channel
# Done automatically by the client
chat.partChannel(channel="#lobby", token=userToken, kick=True) chat.partChannel(channel="#lobby", token=userToken, kick=True)
# Console output # Console output

View File

@ -1,29 +1,2 @@
from objects import glob def handle(userToken, _=None):
from helpers import chatHelper as chat userToken.leaveMatch()
def handle(userToken, _):
# get data from usertoken
userID = userToken.userID
# Get match ID and match object
matchID = userToken.matchID
# Make sure we are in a match
if matchID == -1:
return
# Make sure the match exists
if matchID not in glob.matches.matches:
return
# The match exists, get object
match = glob.matches.matches[matchID]
# Set slot to free
match.userLeft(userID)
# Part #multiplayer channel
#chat.partChannel(token=userToken, channel="#multi_{}".format(matchID), kick=True)
# Set usertoken match to -1
userToken.partMatch()

View File

@ -1,11 +1,7 @@
from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from helpers import userHelper
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
log.debug("Requested status update")
# Update cache and send new stats # Update cache and send new stats
userToken.updateCachedStats() userToken.updateCachedStats()
userToken.enqueue(serverPackets.userStats(userToken.userID)) userToken.enqueue(serverPackets.userStats(userToken.userID))

View File

@ -1,6 +1,8 @@
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from helpers import logHelper as log from objects import glob
def handle(userToken, packetData): def handle(userToken, packetData):
# get token data # get token data
@ -10,12 +12,12 @@ def handle(userToken, packetData):
packetData = clientPackets.setAwayMessage(packetData) packetData = clientPackets.setAwayMessage(packetData)
# Set token away message # Set token away message
userToken.setAwayMessage(packetData["awayMessage"]) userToken.awayMessage = packetData["awayMessage"]
# Send private message from fokabot # Send private message from fokabot
if packetData["awayMessage"] == "": if packetData["awayMessage"] == "":
fokaMessage = "Your away message has been reset" fokaMessage = "Your away message has been reset"
else: else:
fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"]) fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"])
userToken.enqueue(serverPackets.sendMessage("FokaBot", username, fokaMessage)) userToken.enqueue(serverPackets.sendMessage(glob.BOT_NAME, username, fokaMessage))
log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"])) log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"]))

View File

@ -1,30 +1,15 @@
from objects import glob from objects import glob
from constants import serverPackets from constants import serverPackets
from constants import exceptions from common.log import logUtils as log
def handle(userToken, packetData): def handle(userToken, packetData):
# get token data # get token data
userID = userToken.userID userID = userToken.userID
# Send spectator frames to every spectator # Send spectator frames to every spectator
for i in userToken.spectators: streamName = "spect/{}".format(userID)
# Send to every user but host glob.streams.broadcast(streamName, serverPackets.spectatorFrames(packetData[7:]))
if i != userID: log.debug("Broadcasting {}'s frames to {} clients".format(
try: userID,
# Get spectator token object len(glob.streams.streams[streamName].clients))
spectatorToken = glob.tokens.getTokenFromUserID(i) )
# Make sure the token exists
if spectatorToken == None:
raise exceptions.stopSpectating
# Make sure this user is spectating us
if spectatorToken.spectating != userID:
raise exceptions.stopSpectating
# Everything seems fine, send spectator frames to this spectator
spectatorToken.enqueue(serverPackets.spectatorFrames(packetData[7:]))
except exceptions.stopSpectating:
# Remove this user from spectators
userToken.removeSpectator(i)
userToken.enqueue(serverPackets.removeSpectator(i))

View File

@ -1,56 +1,25 @@
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets
from constants import exceptions from constants import exceptions
from objects import glob from objects import glob
from helpers import userHelper
from helpers import logHelper as log
from helpers import chatHelper as chat
def handle(userToken, packetData): def handle(userToken, packetData):
try: try:
# Get usertoken data
userID = userToken.userID
username = userToken.username
# Start spectating packet # Start spectating packet
packetData = clientPackets.startSpectating(packetData) packetData = clientPackets.startSpectating(packetData)
# Stop spectating old user if needed # If the user id is less than 0, treat this as a stop spectating packet
if userToken.spectating != 0: if packetData["userID"] < 0:
oldTargetToken = glob.tokens.getTokenFromUserID(userToken.spectating)
oldTargetToken.enqueue(serverPackets.removeSpectator(userID))
userToken.stopSpectating() userToken.stopSpectating()
return
# Start spectating new user
userToken.startSpectating(packetData["userID"])
# Get host token # Get host token
targetToken = glob.tokens.getTokenFromUserID(packetData["userID"]) targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
if targetToken == None: if targetToken is None:
raise exceptions.tokenNotFoundException raise exceptions.tokenNotFoundException
# Add us to host's spectators # Start spectating new user
targetToken.addSpectator(userID) userToken.startSpectating(targetToken)
# Send spectator join packet to host
targetToken.enqueue(serverPackets.addSpectator(userID))
# Create and join #spectator (#spect_userid) channel
glob.channels.addTempChannel("#spect_{}".format(targetToken.userID))
chat.joinChannel(token=userToken, channel="#spect_{}".format(targetToken.userID))
if len(targetToken.spectators) == 1:
# First spectator, send #spectator join to host too
chat.joinChannel(token=targetToken, channel="#spect_{}".format(targetToken.userID))
# send fellowSpectatorJoined to all spectators
for spec in targetToken.spectators:
if spec is not userID:
c = glob.tokens.getTokenFromUserID(spec)
userToken.enqueue(serverPackets.fellowSpectatorJoined(c.userID))
c.enqueue(serverPackets.fellowSpectatorJoined(userID))
# Console output
log.info("{} are spectating {}".format(username, userHelper.getUsername(packetData["userID"])))
except exceptions.tokenNotFoundException: except exceptions.tokenNotFoundException:
# Stop spectating if token not found # Stop spectating if token not found
log.warning("Spectator start: token not found") log.warning("Spectator start: token not found")

View File

@ -1,37 +1,2 @@
from objects import glob def handle(userToken, _=None):
from constants import serverPackets userToken.stopSpectating()
from constants import exceptions
from helpers import logHelper as log
from helpers import chatHelper as chat
def handle(userToken, _):
try:
# get user token data
userID = userToken.userID
username = userToken.username
# Remove our userID from host's spectators
target = userToken.spectating
targetToken = glob.tokens.getTokenFromUserID(target)
if targetToken == None:
raise exceptions.tokenNotFoundException
targetToken.removeSpectator(userID)
# Part #spectator channel
chat.partChannel(token=userToken, channel="#spect_{}".format(target))
# Send the spectator left packet to host
targetToken.enqueue(serverPackets.removeSpectator(userID))
for c in targetToken.spectators:
spec = glob.tokens.getTokenFromUserID(c)
spec.enqueue(serverPackets.fellowSpectatorLeft(userID))
#targetToken.enqueue(serverPackets.fellowSpectatorLeft(userID))
# Console output
log.info("{} are no longer spectating {}".format(username, target))
except exceptions.tokenNotFoundException:
log.warning("Spectator stop: token not found")
finally:
# Set our spectating user to 0
userToken.stopSpectating()

View File

@ -0,0 +1,11 @@
from constants import clientPackets
from objects import glob
from helpers import chatHelper as chat
def handle(userToken, packetData):
packetData = clientPackets.tournamentJoinMatchChannel(packetData)
matchID = packetData["matchID"]
if matchID not in glob.matches.matches or not userToken.tournament:
return
userToken.matchID = matchID
chat.joinChannel(token=userToken, channel="#multi_{}".format(matchID), force=True)

View File

@ -0,0 +1,11 @@
from constants import clientPackets
from objects import glob
from helpers import chatHelper as chat
def handle(userToken, packetData):
packetData = clientPackets.tournamentLeaveMatchChannel(packetData)
matchID = packetData["matchID"]
if matchID not in glob.matches.matches or not userToken.tournament:
return
chat.partChannel(token=userToken, channel="#multi_{}".format(matchID), force=True)
userToken.matchID = 0

View File

@ -0,0 +1,10 @@
from constants import clientPackets
from objects import glob
def handle(userToken, packetData):
packetData = clientPackets.tournamentMatchInfoRequest(packetData)
matchID = packetData["matchID"]
if matchID not in glob.matches.matches or not userToken.tournament:
return
with glob.matches.matches[matchID] as m:
userToken.enqueue(m.matchDataCache)

View File

@ -1,6 +1,7 @@
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
# Read userIDs list # Read userIDs list

View File

@ -1,6 +1,7 @@
from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from helpers import logHelper as log
def handle(userToken, packetData): def handle(userToken, packetData):
# Read userIDs list # Read userIDs list

View File

@ -1,16 +1,23 @@
fuck=firetruck fuck=firetruck
shit=shish shit=shish
ass=peach ass=peach
asses=peaches asses=peaches
bitch=fine lady bitch=fine lady
bitches=fine ladies bitches=fine ladies
asshole=donkey asshole=donkey
ass hole=donkey ass hole=donkey
cock=chicken cock=chicken
cocks=chickens cocks=chickens
dick=eggplant dick=eggplant
dicks=eggplants dicks=eggplants
boobs=bob boobs=bob
tits=teeth tits=teeth
cum=yogurt cum=yogurt
cunt=count cunt=count
nigger=flowers
ngger=flowers
niggers=flowers
weed=grass
AQN=meme
theaquila=meme
aquila=meme

4
full_build.sh Normal file
View File

@ -0,0 +1,4 @@
find . -name "*.c" -type f -delete
find . -name "*.o" -type f -delete
find . -name "*.so" -type f -delete
python3 setup.py build_ext --inplace

View File

@ -1,39 +1,48 @@
from helpers import requestHelper import json
from constants import exceptions
import json import tornado.web
from objects import glob import tornado.gen
from helpers import chatHelper
from helpers import logHelper as log from common.sentry import sentry
from common.web import requestsManager
class handler(requestHelper.asyncRequestHandler): from constants import exceptions
def asyncGet(self): from helpers import chatHelper
statusCode = 400 from objects import glob
data = {"message": "unknown error"}
try:
# Check arguments class handler(requestsManager.asyncRequestHandler):
if requestHelper.checkArguments(self.request.arguments, ["k", "to", "msg"]) == False: @tornado.web.asynchronous
raise exceptions.invalidArgumentsException() @tornado.gen.engine
@sentry.captureTornado
# Check ci key def asyncGet(self):
key = self.get_argument("k") statusCode = 400
if key is None or key != glob.conf.config["server"]["cikey"]: data = {"message": "unknown error"}
raise exceptions.invalidArgumentsException() try:
# Check arguments
log.info("API REQUEST FOR FOKABOT MESSAGE AAAAAAA") if not requestsManager.checkArguments(self.request.arguments, ["k", "to", "msg"]):
chatHelper.sendMessage("FokaBot", self.get_argument("to"), self.get_argument("msg")) raise exceptions.invalidArgumentsException()
# Status code and message # Check ci key
statusCode = 200 key = self.get_argument("k")
data["message"] = "ok" if key is None or key != glob.conf.config["server"]["cikey"]:
except exceptions.invalidArgumentsException: raise exceptions.invalidArgumentsException()
statusCode = 400
data["message"] = "invalid parameters" chatHelper.sendMessage(
finally: glob.BOT_NAME,
# Add status code to data self.get_argument("to").encode().decode("ASCII", "ignore"),
data["status"] = statusCode self.get_argument("msg").encode().decode("ASCII", "ignore")
)
# Send response
#self.clear() # Status code and message
self.write(json.dumps(data)) statusCode = 200
self.set_status(statusCode) data["message"] = "ok"
#self.finish(json.dumps(data)) except exceptions.invalidArgumentsException:
statusCode = 400
data["message"] = "invalid parameters"
finally:
# Add status code to data
data["status"] = statusCode
# Send response
self.write(json.dumps(data))
self.set_status(statusCode)

View File

@ -1,23 +1,46 @@
from helpers import requestHelper
from constants import exceptions
import json import json
import tornado.web
import tornado.gen
from common.sentry import sentry
from common.ripple import userUtils
from common.web import requestsManager
from constants import exceptions
from objects import glob from objects import glob
class handler(requestHelper.asyncRequestHandler):
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncGet(self): def asyncGet(self):
statusCode = 400 statusCode = 400
data = {"message": "unknown error"} data = {"message": "unknown error"}
try: try:
# Check arguments # Check arguments
if requestHelper.checkArguments(self.request.arguments, ["u"]) == False: if "u" not in self.request.arguments and "id" not in self.request.arguments:
raise exceptions.invalidArgumentsException() raise exceptions.invalidArgumentsException()
# Get online staus # Get online staus
username = self.get_argument("u") username = None
if username == None: userID = None
if "u" in self.request.arguments:
#username = self.get_argument("u").lower().replace(" ", "_")
username = userUtils.safeUsername(self.get_argument("u"))
else:
try:
userID = int(self.get_argument("id"))
except:
raise exceptions.invalidArgumentsException()
if username is None and userID is None:
data["result"] = False data["result"] = False
else: else:
data["result"] = True if glob.tokens.getTokenFromUsername(username) != None else False if username is not None:
data["result"] = True if glob.tokens.getTokenFromUsername(username, safe=True) is not None else False
else:
data["result"] = True if glob.tokens.getTokenFromUserID(userID) is not None else False
# Status code and message # Status code and message
statusCode = 200 statusCode = 200
@ -30,7 +53,5 @@ class handler(requestHelper.asyncRequestHandler):
data["status"] = statusCode data["status"] = statusCode
# Send response # Send response
#self.clear()
self.write(json.dumps(data)) self.write(json.dumps(data))
self.set_status(statusCode) self.set_status(statusCode)
#self.finish(json.dumps(data))

View File

@ -1,14 +1,23 @@
from helpers import requestHelper
import json import json
import tornado.web
import tornado.gen
from common.sentry import sentry
from common.web import requestsManager
from objects import glob from objects import glob
class handler(requestHelper.asyncRequestHandler):
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncGet(self): def asyncGet(self):
statusCode = 400 statusCode = 400
data = {"message": "unknown error"} data = {"message": "unknown error"}
try: try:
# Get online users count # Get online users count
data["result"] = len(glob.tokens.tokens) data["result"] = int(glob.redis.get("ripple:online_users").decode("utf-8"))
# Status code and message # Status code and message
statusCode = 200 statusCode = 200
@ -18,7 +27,5 @@ class handler(requestHelper.asyncRequestHandler):
data["status"] = statusCode data["status"] = statusCode
# Send response # Send response
#self.clear()
self.write(json.dumps(data)) self.write(json.dumps(data))
self.set_status(statusCode) self.set_status(statusCode)
#self.finish(json.dumps(data))

View File

@ -1,14 +1,23 @@
from helpers import requestHelper
import json import json
import tornado.web
import tornado.gen
from common.sentry import sentry
from common.web import requestsManager
from objects import glob from objects import glob
class handler(requestHelper.asyncRequestHandler):
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncGet(self): def asyncGet(self):
statusCode = 400 statusCode = 400
data = {"message": "unknown error"} data = {"message": "unknown error"}
try: try:
# Get online users count # Get online users count
data["result"] = -1 if glob.restarting == True else 1 data["result"] = -1 if glob.restarting else 1
# Status code and message # Status code and message
statusCode = 200 statusCode = 200
@ -18,7 +27,5 @@ class handler(requestHelper.asyncRequestHandler):
data["status"] = statusCode data["status"] = statusCode
# Send response # Send response
#self.clear()
self.write(json.dumps(data)) self.write(json.dumps(data))
self.set_status(statusCode) self.set_status(statusCode)
#self.finish(json.dumps(data))

View File

@ -1,16 +1,24 @@
from helpers import requestHelper
from helpers import logHelper as log
import json import json
from objects import glob
from constants import exceptions
class handler(requestHelper.asyncRequestHandler): import tornado.web
import tornado.gen
from common.sentry import sentry
from common.web import requestsManager
from constants import exceptions
from objects import glob
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncGet(self): def asyncGet(self):
statusCode = 400 statusCode = 400
data = {"message": "unknown error"} data = {"message": "unknown error"}
try: try:
# Check arguments # Check arguments
if requestHelper.checkArguments(self.request.arguments, ["u"]) == False: if not requestsManager.checkArguments(self.request.arguments, ["u"]):
raise exceptions.invalidArgumentsException() raise exceptions.invalidArgumentsException()
# Get userID and its verified cache thing # Get userID and its verified cache thing

View File

@ -1,17 +1,26 @@
from helpers import requestHelper
from constants import exceptions
import json import json
from objects import glob
from helpers import systemHelper
from helpers import logHelper as log
class handler(requestHelper.asyncRequestHandler): import tornado.web
import tornado.gen
from common.sentry import sentry
from common.log import logUtils as log
from common.web import requestsManager
from constants import exceptions
from helpers import systemHelper
from objects import glob
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncGet(self): def asyncGet(self):
statusCode = 400 statusCode = 400
data = {"message": "unknown error"} data = {"message": "unknown error"}
try: try:
# Check arguments # Check arguments
if requestHelper.checkArguments(self.request.arguments, ["k"]) == False: if not requestsManager.checkArguments(self.request.arguments, ["k"]):
raise exceptions.invalidArgumentsException() raise exceptions.invalidArgumentsException()
# Check ci key # Check ci key
@ -33,7 +42,5 @@ class handler(requestHelper.asyncRequestHandler):
data["status"] = statusCode data["status"] = statusCode
# Send response # Send response
#self.clear()
self.write(json.dumps(data)) self.write(json.dumps(data))
self.set_status(statusCode) self.set_status(statusCode)
#self.finish(json.dumps(data))

25
handlers/heavyHandler.py Normal file
View File

@ -0,0 +1,25 @@
import tornado.gen
import tornado.web
from common.web import requestsManager
from objects import glob
import time
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def asyncGet(self):
if not glob.debug:
self.write("Nope")
return
time.sleep(0.5)
self.write("meemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeemmeem")
self.set_status(200)
self.add_header("cho-token", "tua madre")
self.add_header("cho-protocol", "19")
self.add_header("Connection", "keep-alive")
self.add_header("Keep-Alive", "timeout=5, max=100")
self.add_header("Content-Type", "text/html; charset=UTF-8")
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM beatmaps")
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM users")
#glob.db.fetchAll("SELECT SQL_NO_CACHE * FROM scores")
#self.write("ibmd")

View File

@ -1,264 +0,0 @@
import datetime
import gzip
from helpers import requestHelper
from objects import glob
from constants import exceptions
from constants import packetIDs
from helpers import packetHelper
from constants import serverPackets
from events import sendPublicMessageEvent
from events import sendPrivateMessageEvent
from events import channelJoinEvent
from events import channelPartEvent
from events import changeActionEvent
from events import cantSpectateEvent
from events import startSpectatingEvent
from events import stopSpectatingEvent
from events import spectateFramesEvent
from events import friendAddEvent
from events import friendRemoveEvent
from events import logoutEvent
from events import loginEvent
from events import setAwayMessageEvent
from events import joinLobbyEvent
from events import createMatchEvent
from events import partLobbyEvent
from events import changeSlotEvent
from events import joinMatchEvent
from events import partMatchEvent
from events import changeMatchSettingsEvent
from events import changeMatchPasswordEvent
from events import changeMatchModsEvent
from events import matchReadyEvent
from events import matchLockEvent
from events import matchStartEvent
from events import matchPlayerLoadEvent
from events import matchSkipEvent
from events import matchFramesEvent
from events import matchCompleteEvent
from events import matchNoBeatmapEvent
from events import matchHasBeatmapEvent
from events import matchTransferHostEvent
from events import matchFailedEvent
from events import matchInviteEvent
from events import matchChangeTeamEvent
from events import userStatsRequestEvent
from events import requestStatusUpdateEvent
from events import userPanelRequestEvent
# Exception tracking
import tornado.web
import tornado.gen
import sys
import traceback
from raven.contrib.tornado import SentryMixin
from helpers import logHelper as log
class handler(SentryMixin, requestHelper.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def asyncPost(self):
try:
# Track time if needed
if glob.outputRequestTime == True:
# Start time
st = datetime.datetime.now()
# Client's token string and request data
requestTokenString = self.request.headers.get("osu-token")
requestData = self.request.body
# Server's token string and request data
responseTokenString = "ayy"
responseData = bytes()
if requestTokenString == None:
# No token, first request. Handle login.
responseTokenString, responseData = loginEvent.handle(self)
else:
userToken = None # default value
try:
# This is not the first packet, send response based on client's request
# Packet start position, used to read stacked packets
pos = 0
# Make sure the token exists
if requestTokenString not in glob.tokens.tokens:
raise exceptions.tokenNotFoundException()
# Token exists, get its object and lock it
userToken = glob.tokens.tokens[requestTokenString]
userToken.lock.acquire()
# Keep reading packets until everything has been read
while pos < len(requestData):
# Get packet from stack starting from new packet
leftData = requestData[pos:]
# Get packet ID, data length and data
packetID = packetHelper.readPacketID(leftData)
dataLength = packetHelper.readPacketLength(leftData)
packetData = requestData[pos:(pos+dataLength+7)]
# Console output if needed
if glob.outputPackets == True and packetID != 4:
log.debug("Incoming packet ({})({}):\n\nPacket code: {}\nPacket length: {}\nSingle packet data: {}\n".format(requestTokenString, userToken.username, str(packetID), str(dataLength), str(packetData)))
# Event handler
def handleEvent(ev):
def wrapper():
ev.handle(userToken, packetData)
return wrapper
eventHandler = {
# TODO: Rename packets and events
# TODO: Host check for multi
packetIDs.client_changeAction: handleEvent(changeActionEvent),
packetIDs.client_logout: handleEvent(logoutEvent),
packetIDs.client_friendAdd: handleEvent(friendAddEvent),
packetIDs.client_friendRemove: handleEvent(friendRemoveEvent),
packetIDs.client_userStatsRequest: handleEvent(userStatsRequestEvent),
packetIDs.client_requestStatusUpdate: handleEvent(requestStatusUpdateEvent),
packetIDs.client_userPanelRequest: handleEvent(userPanelRequestEvent),
packetIDs.client_channelJoin: handleEvent(channelJoinEvent),
packetIDs.client_channelPart: handleEvent(channelPartEvent),
packetIDs.client_sendPublicMessage: handleEvent(sendPublicMessageEvent),
packetIDs.client_sendPrivateMessage: handleEvent(sendPrivateMessageEvent),
packetIDs.client_setAwayMessage: handleEvent(setAwayMessageEvent),
packetIDs.client_startSpectating: handleEvent(startSpectatingEvent),
packetIDs.client_stopSpectating: handleEvent(stopSpectatingEvent),
packetIDs.client_cantSpectate: handleEvent(cantSpectateEvent),
packetIDs.client_spectateFrames: handleEvent(spectateFramesEvent),
packetIDs.client_joinLobby: handleEvent(joinLobbyEvent),
packetIDs.client_partLobby: handleEvent(partLobbyEvent),
packetIDs.client_createMatch: handleEvent(createMatchEvent),
packetIDs.client_joinMatch: handleEvent(joinMatchEvent),
packetIDs.client_partMatch: handleEvent(partMatchEvent),
packetIDs.client_matchChangeSlot: handleEvent(changeSlotEvent),
packetIDs.client_matchChangeSettings: handleEvent(changeMatchSettingsEvent),
packetIDs.client_matchChangePassword: handleEvent(changeMatchPasswordEvent),
packetIDs.client_matchChangeMods: handleEvent(changeMatchModsEvent),
packetIDs.client_matchReady: handleEvent(matchReadyEvent),
packetIDs.client_matchNotReady: handleEvent(matchReadyEvent),
packetIDs.client_matchLock: handleEvent(matchLockEvent),
packetIDs.client_matchStart: handleEvent(matchStartEvent),
packetIDs.client_matchLoadComplete: handleEvent(matchPlayerLoadEvent),
packetIDs.client_matchSkipRequest: handleEvent(matchSkipEvent),
packetIDs.client_matchScoreUpdate: handleEvent(matchFramesEvent),
packetIDs.client_matchComplete: handleEvent(matchCompleteEvent),
packetIDs.client_matchNoBeatmap: handleEvent(matchNoBeatmapEvent),
packetIDs.client_matchHasBeatmap: handleEvent(matchHasBeatmapEvent),
packetIDs.client_matchTransferHost: handleEvent(matchTransferHostEvent),
packetIDs.client_matchFailed: handleEvent(matchFailedEvent),
packetIDs.client_matchChangeTeam: handleEvent(matchChangeTeamEvent),
packetIDs.client_invite: handleEvent(matchInviteEvent),
}
# Packets processed if in restricted mode.
# All other packets will be ignored if the user is in restricted mode
packetsRestricted = [
packetIDs.client_logout,
packetIDs.client_userStatsRequest,
packetIDs.client_requestStatusUpdate,
packetIDs.client_userPanelRequest,
packetIDs.client_changeAction,
packetIDs.client_channelJoin,
packetIDs.client_channelPart,
]
# Process/ignore packet
if packetID != 4:
if packetID in eventHandler:
if userToken.restricted == False or (userToken.restricted == True and packetID in packetsRestricted):
eventHandler[packetID]()
else:
log.warning("Ignored packet id from {} ({}) (user is restricted)".format(requestTokenString, packetID))
else:
log.warning("Unknown packet id from {} ({})".format(requestTokenString, packetID))
# Update pos so we can read the next stacked packet
# +7 because we add packet ID bytes, unused byte and data length bytes
pos += dataLength+7
# Token queue built, send it
responseTokenString = userToken.token
responseData = userToken.queue
userToken.resetQueue()
# Update ping time for timeout
userToken.updatePingTime()
except exceptions.tokenNotFoundException:
# Token not found. Disconnect that user
responseData = serverPackets.loginError()
responseData += serverPackets.notification("Whoops! Something went wrong, please login again.")
log.warning("Received packet from unknown token ({}).".format(requestTokenString))
log.info("{} has been disconnected (invalid token)".format(requestTokenString))
finally:
# Unlock token
if userToken != None:
userToken.lock.release()
if glob.outputRequestTime == True:
# End time
et = datetime.datetime.now()
# Total time:
tt = float((et.microsecond-st.microsecond)/1000)
log.debug("Request time: {}ms".format(tt))
# Send server's response to client
# We don't use token object because we might not have a token (failed login)
if glob.gzip == True:
# First, write the gzipped response
self.write(gzip.compress(responseData, int(glob.conf.config["server"]["gziplevel"])))
# Then, add gzip headers
self.add_header("Vary", "Accept-Encoding")
self.add_header("Content-Encoding", "gzip")
else:
# First, write the response
self.write(responseData)
# Add all the headers AFTER the response has been written
self.set_status(200)
self.add_header("cho-token", responseTokenString)
self.add_header("cho-protocol", "19")
#self.add_header("Keep-Alive", "timeout=5, max=100")
#self.add_header("Connection", "keep-alive")
self.add_header("Content-Type", "text/html; charset=UTF-8")
except:
log.error("Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
if glob.sentry:
yield tornado.gen.Task(self.captureException, exc_info=True)
#finally:
# self.finish()
@tornado.web.asynchronous
@tornado.gen.engine
def asyncGet(self):
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%}</style></head><body><pre>"
html += " _ __<br>"
html += " (_) / /<br>"
html += " ______ __ ____ ____ / /____<br>"
html += " / ___/ / _ \\/ _ \\/ / _ \\<br>"
html += " / / / / /_) / /_) / / ____/<br>"
html += "/__/ /__/ .___/ .___/__/ \\_____/<br>"
html += " / / / /<br>"
html += " /__/ /__/<br>"
html += "<b>PYTHON > ALL VERSION</b><br><br>"
html += "<marquee style='white-space:pre;'><br>"
html += " .. o .<br>"
html += " o.o o . o<br>"
html += " oo...<br>"
html += " __[]__<br>"
html += " phwr--> _\\:D/_/o_o_o_|__ <span style=\"font-family: 'Comic Sans MS'; font-size: 8pt;\">u wot m8</span><br>"
html += " \\\"\"\"\"\"\"\"\"\"\"\"\"\"\"/<br>"
html += " \\ . .. .. . /<br>"
html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>"
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.<br><br><i>&copy; Ripple team, 2016</i></pre></body></html>"
self.write(html)
#yield tornado.gen.Task(self.captureMessage, "test")
#self.finish()

266
handlers/mainHandler.pyx Normal file
View File

@ -0,0 +1,266 @@
import datetime
import gzip
import sys
import traceback
import tornado.gen
import tornado.web
from raven.contrib.tornado import SentryMixin
from common.log import logUtils as log
from common.web import requestsManager
from constants import exceptions
from constants import packetIDs
from constants import serverPackets
from events import cantSpectateEvent
from events import changeActionEvent
from events import changeMatchModsEvent
from events import changeMatchPasswordEvent
from events import changeMatchSettingsEvent
from events import changeSlotEvent
from events import channelJoinEvent
from events import channelPartEvent
from events import createMatchEvent
from events import friendAddEvent
from events import friendRemoveEvent
from events import joinLobbyEvent
from events import joinMatchEvent
from events import loginEvent
from events import logoutEvent
from events import matchChangeTeamEvent
from events import matchCompleteEvent
from events import matchFailedEvent
from events import matchFramesEvent
from events import matchHasBeatmapEvent
from events import matchInviteEvent
from events import matchLockEvent
from events import matchNoBeatmapEvent
from events import matchPlayerLoadEvent
from events import matchReadyEvent
from events import matchSkipEvent
from events import matchStartEvent
from events import matchTransferHostEvent
from events import partLobbyEvent
from events import partMatchEvent
from events import requestStatusUpdateEvent
from events import sendPrivateMessageEvent
from events import sendPublicMessageEvent
from events import setAwayMessageEvent
from events import spectateFramesEvent
from events import startSpectatingEvent
from events import stopSpectatingEvent
from events import userPanelRequestEvent
from events import userStatsRequestEvent
from events import tournamentMatchInfoRequestEvent
from events import tournamentJoinMatchChannelEvent
from events import tournamentLeaveMatchChannelEvent
from helpers import packetHelper
from objects import glob
from common.sentry import sentry
class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
@sentry.captureTornado
def asyncPost(self):
# Track time if needed
if glob.outputRequestTime:
# Start time
st = datetime.datetime.now()
# Client's token string and request data
requestTokenString = self.request.headers.get("osu-token")
requestData = self.request.body
# Server's token string and request data
responseTokenString = "ayy"
responseData = bytes()
if requestTokenString is None:
# No token, first request. Handle login.
responseTokenString, responseData = loginEvent.handle(self)
else:
userToken = None # default value
try:
# This is not the first packet, send response based on client's request
# Packet start position, used to read stacked packets
pos = 0
# Make sure the token exists
if requestTokenString not in glob.tokens.tokens:
raise exceptions.tokenNotFoundException()
# Token exists, get its object and lock it
userToken = glob.tokens.tokens[requestTokenString]
userToken.processingLock.acquire()
# Keep reading packets until everything has been read
while pos < len(requestData):
# Get packet from stack starting from new packet
leftData = requestData[pos:]
# Get packet ID, data length and data
packetID = packetHelper.readPacketID(leftData)
dataLength = packetHelper.readPacketLength(leftData)
packetData = requestData[pos:(pos+dataLength+7)]
# Console output if needed
if glob.outputPackets and packetID != 4:
log.debug("Incoming packet ({})({}):\n\nPacket code: {}\nPacket length: {}\nSingle packet data: {}\n".format(requestTokenString, userToken.username, str(packetID), str(dataLength), str(packetData)))
# Event handler
def handleEvent(ev):
def wrapper():
ev.handle(userToken, packetData)
return wrapper
eventHandler = {
packetIDs.client_changeAction: handleEvent(changeActionEvent),
packetIDs.client_logout: handleEvent(logoutEvent),
packetIDs.client_friendAdd: handleEvent(friendAddEvent),
packetIDs.client_friendRemove: handleEvent(friendRemoveEvent),
packetIDs.client_userStatsRequest: handleEvent(userStatsRequestEvent),
packetIDs.client_requestStatusUpdate: handleEvent(requestStatusUpdateEvent),
packetIDs.client_userPanelRequest: handleEvent(userPanelRequestEvent),
packetIDs.client_channelJoin: handleEvent(channelJoinEvent),
packetIDs.client_channelPart: handleEvent(channelPartEvent),
packetIDs.client_sendPublicMessage: handleEvent(sendPublicMessageEvent),
packetIDs.client_sendPrivateMessage: handleEvent(sendPrivateMessageEvent),
packetIDs.client_setAwayMessage: handleEvent(setAwayMessageEvent),
packetIDs.client_startSpectating: handleEvent(startSpectatingEvent),
packetIDs.client_stopSpectating: handleEvent(stopSpectatingEvent),
packetIDs.client_cantSpectate: handleEvent(cantSpectateEvent),
packetIDs.client_spectateFrames: handleEvent(spectateFramesEvent),
packetIDs.client_joinLobby: handleEvent(joinLobbyEvent),
packetIDs.client_partLobby: handleEvent(partLobbyEvent),
packetIDs.client_createMatch: handleEvent(createMatchEvent),
packetIDs.client_joinMatch: handleEvent(joinMatchEvent),
packetIDs.client_partMatch: handleEvent(partMatchEvent),
packetIDs.client_matchChangeSlot: handleEvent(changeSlotEvent),
packetIDs.client_matchChangeSettings: handleEvent(changeMatchSettingsEvent),
packetIDs.client_matchChangePassword: handleEvent(changeMatchPasswordEvent),
packetIDs.client_matchChangeMods: handleEvent(changeMatchModsEvent),
packetIDs.client_matchReady: handleEvent(matchReadyEvent),
packetIDs.client_matchNotReady: handleEvent(matchReadyEvent),
packetIDs.client_matchLock: handleEvent(matchLockEvent),
packetIDs.client_matchStart: handleEvent(matchStartEvent),
packetIDs.client_matchLoadComplete: handleEvent(matchPlayerLoadEvent),
packetIDs.client_matchSkipRequest: handleEvent(matchSkipEvent),
packetIDs.client_matchScoreUpdate: handleEvent(matchFramesEvent),
packetIDs.client_matchComplete: handleEvent(matchCompleteEvent),
packetIDs.client_matchNoBeatmap: handleEvent(matchNoBeatmapEvent),
packetIDs.client_matchHasBeatmap: handleEvent(matchHasBeatmapEvent),
packetIDs.client_matchTransferHost: handleEvent(matchTransferHostEvent),
packetIDs.client_matchFailed: handleEvent(matchFailedEvent),
packetIDs.client_matchChangeTeam: handleEvent(matchChangeTeamEvent),
packetIDs.client_invite: handleEvent(matchInviteEvent),
packetIDs.client_tournamentMatchInfoRequest: handleEvent(tournamentMatchInfoRequestEvent),
packetIDs.client_tournamentJoinMatchChannel: handleEvent(tournamentJoinMatchChannelEvent),
packetIDs.client_tournamentLeaveMatchChannel: handleEvent(tournamentLeaveMatchChannelEvent),
}
# Packets processed if in restricted mode.
# All other packets will be ignored if the user is in restricted mode
packetsRestricted = [
packetIDs.client_logout,
packetIDs.client_userStatsRequest,
packetIDs.client_requestStatusUpdate,
packetIDs.client_userPanelRequest,
packetIDs.client_changeAction,
packetIDs.client_channelJoin,
packetIDs.client_channelPart,
]
# Process/ignore packet
if packetID != 4:
if packetID in eventHandler:
if not userToken.restricted or (userToken.restricted and packetID in packetsRestricted):
eventHandler[packetID]()
else:
log.warning("Ignored packet id from {} ({}) (user is restricted)".format(requestTokenString, packetID))
else:
log.warning("Unknown packet id from {} ({})".format(requestTokenString, packetID))
# Update pos so we can read the next stacked packet
# +7 because we add packet ID bytes, unused byte and data length bytes
pos += dataLength+7
# Token queue built, send it
responseTokenString = userToken.token
responseData = userToken.queue
userToken.resetQueue()
except exceptions.tokenNotFoundException:
# Token not found. Disconnect that user
responseData = serverPackets.loginError()
responseData += serverPackets.notification("Whoops! Something went wrong, please login again.")
log.warning("Received packet from unknown token ({}).".format(requestTokenString))
log.info("{} has been disconnected (invalid token)".format(requestTokenString))
finally:
# Unlock token
if userToken is not None:
# Update ping time for timeout
userToken.updatePingTime()
# Release processing lock
userToken.processingLock.release()
# Delete token if kicked
if userToken.kicked:
glob.tokens.deleteToken(userToken)
if glob.outputRequestTime:
# End time
et = datetime.datetime.now()
# Total time:
tt = float((et.microsecond-st.microsecond)/1000)
log.debug("Request time: {}ms".format(tt))
# Send server's response to client
# We don't use token object because we might not have a token (failed login)
if glob.gzip:
# First, write the gzipped response
self.write(gzip.compress(responseData, int(glob.conf.config["server"]["gziplevel"])))
# Then, add gzip headers
self.add_header("Vary", "Accept-Encoding")
self.add_header("Content-Encoding", "gzip")
else:
# First, write the response
self.write(responseData)
# Add all the headers AFTER the response has been written
self.set_status(200)
self.add_header("cho-token", responseTokenString)
self.add_header("cho-protocol", "19")
self.add_header("Connection", "keep-alive")
self.add_header("Keep-Alive", "timeout=5, max=100")
self.add_header("Content-Type", "text/html; charset=UTF-8")
@tornado.web.asynchronous
@tornado.gen.engine
def asyncGet(self):
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%;background:#222;color:#fff;}</style></head><body><pre>"
html += " _ __<br>"
html += " (_) / /<br>"
html += " ______ __ ____ ____ / /____<br>"
html += " / ___/ / _ \\/ _ \\/ / _ \\<br>"
html += " / / / / /_) / /_) / / ____/<br>"
html += "/__/ /__/ .___/ .___/__/ \\_____/<br>"
html += " / / / /<br>"
html += " /__/ /__/<br>"
html += "<b>PYTHON > ALL VERSION</b><br><br>"
html += "<marquee style='white-space:pre;'><br>"
html += " .. o .<br>"
html += " o.o o . o<br>"
html += " oo...<br>"
html += " __[]__<br>"
html += " phwr--> _\\:D/_/o_o_o_|__ <span style=\"font-family: 'Comic Sans MS'; font-size: 8pt;\">u wot m8</span><br>"
html += " \\\"\"\"\"\"\"\"\"\"\"\"\"\"\"/<br>"
html += " \\ . .. .. . /<br>"
html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>"
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.<br><br>Running osufx branch.<br><i>&copy; Ripple team, 2016</i></pre></body></html>"
self.write(html)

View File

@ -1,52 +0,0 @@
"""
WIP feature that will come in the future.
Don't import
"""
import flask
from objects import glob
from constants import exceptions
@app.route("/api/online-users-count")
def APIonlineUsersCount():
return flask.jsonify({"count" : len(glob.tokens.tokens)-1})
@app.route("/api/user-info")
def APIonlineUsers():
resp = {}
try:
u = flask.request.args.get('u')
# Username/userID
if u.isdigit():
u = int(u)
else:
u = userHelper.getID(u)
if u == None:
raise exceptions.userNotFoundException
# Make sure this user is online
userToken = glob.tokens.getTokenFromUserID(u)
if userToken == None:
raise exceptions.tokenNotFoundException
# Build response dictionary
resp["response"] = "1"
resp[userToken.username] = {
"userID" : userToken.userID,
"actionID" : userToken.actionID,
"actionText" : userToken.actionText,
"actionMd5" : userToken.actionMd5,
"actionMods": userToken.actionMods,
"gameMode": userToken.gameMode,
"country": countryHelper.getCountryLetters(userToken.country),
"position": userToken.location,
"spectating": userToken.spectating,
"spectators": userToken.spectators
}
except exceptions.userNotFoundException:
resp["response"] = "-1"
except exceptions.tokenNotFoundException:
resp["response"] = "-2"
finally:
return flask.jsonify(resp)

View File

@ -1,114 +1,103 @@
from objects import glob from common.log import logUtils as log
from helpers import logHelper as log from common.ripple import userUtils
from constants import exceptions from constants import exceptions
from constants import serverPackets
from objects import fokabot
from helpers import discordBotHelper
from helpers import userHelper
from events import logoutEvent
from constants import messageTemplates from constants import messageTemplates
from constants import serverPackets
from events import logoutEvent
from objects import fokabot
from objects import glob
def joinChannel(userID = 0, channel = "", token = None, toIRC = True):
def joinChannel(userID = 0, channel = "", token = None, toIRC = True, force=False):
""" """
Join a channel Join a channel
userID -- user ID of the user that joins the channel. Optional. :param userID: user ID of the user that joins the channel. Optional. token can be used instead.
token can be used instead. :param token: user token object of user that joins the channel. Optional. userID can be used instead.
token -- user token object of user that joins the channel. Optional. :param channel: channel name
userID can be used instead. :param toIRC: if True, send this channel join event to IRC. Must be true if joining from bancho. Default: True
channel -- name of channe :param force: whether to allow game clients to join #spect_ and #multi_ channels
toIRC -- if True, send this channel join event to IRC. Must be true if joining from bancho. :return: 0 if joined or other IRC code in case of error. Needed only on IRC-side
Optional. Defaukt: True
return -- returns 0 if joined or other IRC code in case of error. Needed only on IRC-side
""" """
try: try:
# Get token if not defined # Get token if not defined
if token == None: if token is None:
token = glob.tokens.getTokenFromUserID(userID) token = glob.tokens.getTokenFromUserID(userID)
# Make sure the token exists # Make sure the token exists
if token == None: if token is None:
raise exceptions.userNotFoundException raise exceptions.userNotFoundException
else: else:
token = token token = token
userID = token.userID
# Get usertoken data
username = token.username
# Normal channel, do check stuff # Normal channel, do check stuff
# Make sure the channel exists # Make sure the channel exists
if channel not in glob.channels.channels: if channel not in glob.channels.channels:
raise exceptions.channelUnknownException raise exceptions.channelUnknownException()
# Check channel permissions # Make sure a game client is not trying to join a #multi_ or #spect_ channel manually
channelObject = glob.channels.channels[channel] channelObject = glob.channels.channels[channel]
if channelObject.publicRead == False and token.admin == False: if channelObject.isSpecial and not token.irc and not force:
raise exceptions.channelNoPermissionsException raise exceptions.channelUnknownException()
# Add our userID to users in that channel
channelObject.userJoin(userID)
# Add the channel to our joined channel # Add the channel to our joined channel
token.joinChannel(channel) token.joinChannel(channelObject)
# Send channel joined (bancho). We use clientName here because of #multiplayer and #spectator channels
token.enqueue(serverPackets.channelJoinSuccess(userID, channelObject.clientName))
# Send channel joined (IRC) # Send channel joined (IRC)
if glob.irc == True and toIRC == True: if glob.irc and not toIRC:
glob.ircServer.banchoJoinChannel(username, channel) glob.ircServer.banchoJoinChannel(token.username, channel)
# Console output # Console output
log.info("{} joined channel {}".format(username, channel)) log.info("{} joined channel {}".format(token.username, channel))
# IRC code return # IRC code return
return 0 return 0
except exceptions.channelNoPermissionsException: except exceptions.channelNoPermissionsException:
log.warning("{} attempted to join channel {}, but they have no read permissions".format(username, channel)) log.warning("{} attempted to join channel {}, but they have no read permissions".format(token.username, channel))
return 403 return 403
except exceptions.channelUnknownException: except exceptions.channelUnknownException:
log.warning("{} attempted to join an unknown channel ({})".format(username, channel)) log.warning("{} attempted to join an unknown channel ({})".format(token.username, channel))
return 403
except exceptions.userAlreadyInChannelException:
log.warning("User {} already in channel {}".format(token.username, channel))
return 403 return 403
except exceptions.userNotFoundException: except exceptions.userNotFoundException:
log.warning("User not connected to IRC/Bancho") log.warning("User not connected to IRC/Bancho")
return 403 # idk return 403 # idk
def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = False): def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = False, force=False):
""" """
Part a channel Part a channel
userID -- user ID of the user that parts the channel. Optional. :param userID: user ID of the user that parts the channel. Optional. token can be used instead.
token can be used instead. :param token: user token object of user that parts the channel. Optional. userID can be used instead.
token -- user token object of user that parts the channel. Optional. :param channel: channel name
userID can be used instead. :param toIRC: if True, send this channel join event to IRC. Must be true if joining from bancho. Optional. Default: True
channel -- name of channel :param kick: if True, channel tab will be closed on client. Used when leaving lobby. Optional. Default: False
toIRC -- if True, send this channel join event to IRC. Must be true if joining from bancho. :param force: whether to allow game clients to part #spect_ and #multi_ channels
Optional. Defaukt: True :return: 0 if joined or other IRC code in case of error. Needed only on IRC-side
kick -- if True, channel tab will be closed on client. Used when leaving lobby. Optional. Default: False
return -- returns 0 if joined or other IRC code in case of error. Needed only on IRC-side
""" """
try: try:
# Make sure the client is not drunk and sends partChannel when closing a PM tab
if not channel.startswith("#"):
return
# Get token if not defined # Get token if not defined
if token == None: if token is None:
token = glob.tokens.getTokenFromUserID(userID) token = glob.tokens.getTokenFromUserID(userID)
# Make sure the token exists # Make sure the token exists
if token == None: if token is None:
raise exceptions.userNotFoundException raise exceptions.userNotFoundException()
else: else:
token = token token = token
userID = token.userID
# Get usertoken data
username = token.username
# Determine internal/client name if needed # Determine internal/client name if needed
# (toclient is used clientwise for #multiplayer and #spectator channels) # (toclient is used clientwise for #multiplayer and #spectator channels)
channelClient = channel channelClient = channel
if channel == "#spectator": if channel == "#spectator":
if token.spectating == 0: if token.spectating is None:
s = userID s = userID
else: else:
s = token.spectating s = token.spectatingUserID
channel = "#spect_{}".format(s) channel = "#spect_{}".format(s)
elif channel == "#multiplayer": elif channel == "#multiplayer":
channel = "#multi_{}".format(token.matchID) channel = "#multi_{}".format(token.matchID)
@ -119,84 +108,96 @@ def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = Fal
# Make sure the channel exists # Make sure the channel exists
if channel not in glob.channels.channels: if channel not in glob.channels.channels:
raise exceptions.channelUnknownException raise exceptions.channelUnknownException()
# Make sure a game client is not trying to join a #multi_ or #spect_ channel manually
channelObject = glob.channels.channels[channel]
if channelObject.isSpecial and not token.irc and not force:
raise exceptions.channelUnknownException()
# Make sure the user is in the channel
if channel not in token.joinedChannels:
raise exceptions.userNotInChannelException()
# Part channel (token-side and channel-side) # Part channel (token-side and channel-side)
channelObject = glob.channels.channels[channel] token.partChannel(channelObject)
token.partChannel(channel)
channelObject.userPart(userID) # Delete temporary channel if everyone left
if "chat/{}".format(channelObject.name) in glob.streams.streams:
if channelObject.temp and len(glob.streams.streams["chat/{}".format(channelObject.name)].clients) - 1 == 0:
glob.channels.removeChannel(channelObject.name)
# Force close tab if needed # Force close tab if needed
# NOTE: Maybe always needed, will check later # NOTE: Maybe always needed, will check later
if kick == True: if kick:
token.enqueue(serverPackets.channelKicked(channelClient)) token.enqueue(serverPackets.channelKicked(channelClient))
# IRC part # IRC part
if glob.irc == True and toIRC == True: if glob.irc and toIRC:
glob.ircServer.banchoPartChannel(username, channel) glob.ircServer.banchoPartChannel(token.username, channel)
# Console output # Console output
log.info("{} parted channel {} ({})".format(username, channel, channelClient)) log.info("{} parted channel {} ({})".format(token.username, channel, channelClient))
# Return IRC code # Return IRC code
return 0 return 0
except exceptions.channelUnknownException: except exceptions.channelUnknownException:
log.warning("{} attempted to part an unknown channel ({})".format(username, channel)) log.warning("{} attempted to part an unknown channel ({})".format(token.username, channel))
return 403 return 403
except exceptions.userNotInChannelException:
log.warning("{} attempted to part {}, but he's not in that channel".format(token.username, channel))
return 442
except exceptions.userNotFoundException: except exceptions.userNotFoundException:
log.warning("User not connected to IRC/Bancho") log.warning("User not connected to IRC/Bancho")
return 442 # idk return 442 # idk
def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True): def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
""" """
Send a message to osu!bancho and IRC server Send a message to osu!bancho and IRC server
fro -- sender username. Optional. :param fro: sender username. Optional. token can be used instead
You can use token instead of this if you wish. :param to: receiver channel (if starts with #) or username
to -- receiver channel (if starts with #) or username :param message: text of the message
message -- text of the message :param token: sender token object. Optional. fro can be used instead
token -- sender token object. :param toIRC: if True, send the message to IRC. If False, send it to Bancho only. Default: True
You can use this instead of fro if you are sending messages from bancho. :return: 0 if joined or other IRC code in case of error. Needed only on IRC-side
Optional.
toIRC -- if True, send the message to IRC. If False, send it to Bancho only.
Optional. Default: True
""" """
try: try:
tokenString = "" #tokenString = ""
# Get token object if not passed # Get token object if not passed
if token == None: if token is None:
token = glob.tokens.getTokenFromUsername(fro) token = glob.tokens.getTokenFromUsername(fro)
if token == None: if token is None:
raise exceptions.userNotFoundException raise exceptions.userNotFoundException()
else: else:
# token object alredy passed, get its string and its username (fro) # token object alredy passed, get its string and its username (fro)
fro = token.username fro = token.username
tokenString = token.token #tokenString = token.token
# Set some variables # Make sure this is not a tournament client
userID = token.userID # if token.tournament:
username = token.username # raise exceptions.userTournamentException()
recipients = []
# Make sure the user is not in restricted mode # Make sure the user is not in restricted mode
if token.restricted == True: if token.restricted:
raise exceptions.userRestrictedException raise exceptions.userRestrictedException()
# Make sure the user is not silenced # Make sure the user is not silenced
if token.isSilenced() == True: if token.isSilenced():
raise exceptions.userSilencedException raise exceptions.userSilencedException()
# Redirect !report to FokaBot
if message.startswith("!report"):
to = glob.BOT_NAME
# Determine internal name if needed # Determine internal name if needed
# (toclient is used clientwise for #multiplayer and #spectator channels) # (toclient is used clientwise for #multiplayer and #spectator channels)
toClient = to toClient = to
if to == "#spectator": if to == "#spectator":
if token.spectating == 0: if token.spectating is None:
s = userID s = token.userID
else: else:
s = token.spectating s = token.spectatingUserID
to = "#spect_{}".format(s) to = "#spect_{}".format(s)
elif to == "#multiplayer": elif to == "#multiplayer":
to = "#multi_{}".format(token.matchID) to = "#multi_{}".format(token.matchID)
@ -205,6 +206,10 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
elif to.startswith("#multi_"): elif to.startswith("#multi_"):
toClient = "#multiplayer" toClient = "#multiplayer"
# Make sure the message is valid
if not message.strip():
raise exceptions.invalidArgumentsException()
# Truncate message if > 2048 characters # Truncate message if > 2048 characters
message = message[:2048]+"..." if len(message) > 2048 else message message = message[:2048]+"..." if len(message) > 2048 else message
@ -212,116 +217,185 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
message = glob.chatFilters.filterMessage(message) message = glob.chatFilters.filterMessage(message)
# Build packet bytes # Build packet bytes
packet = serverPackets.sendMessage(username, toClient, message) packet = serverPackets.sendMessage(token.username, toClient, message)
# Send the message # Send the message
isChannel = to.startswith("#") isChannel = to.startswith("#")
if isChannel == True: if isChannel:
# CHANNEL # CHANNEL
# Make sure the channel exists # Make sure the channel exists
if to not in glob.channels.channels: if to not in glob.channels.channels:
raise exceptions.channelUnknownException raise exceptions.channelUnknownException()
# Make sure the channel is not in moderated mode # Make sure the channel is not in moderated mode
if glob.channels.channels[to].moderated == True and token.admin == False: if glob.channels.channels[to].moderated and not token.admin:
raise exceptions.channelModeratedException raise exceptions.channelModeratedException()
# Make sure we are in the channel
if to not in token.joinedChannels:
# I'm too lazy to put and test the correct IRC error code here...
# but IRC is not strict at all so who cares
raise exceptions.channelNoPermissionsException()
# Make sure we have write permissions # Make sure we have write permissions
if glob.channels.channels[to].publicWrite == False and token.admin == False: if not glob.channels.channels[to].publicWrite and not token.admin:
raise exceptions.channelNoPermissionsException raise exceptions.channelNoPermissionsException()
# Add message in buffer
token.addMessageInBuffer(to, message)
# Everything seems fine, build recipients list and send packet # Everything seems fine, build recipients list and send packet
recipients = glob.channels.channels[to].getConnectedUsers()[:] glob.streams.broadcast("chat/{}".format(to), packet, but=[token.token])
for key, value in glob.tokens.tokens.items():
# Skip our client and irc clients
if key == tokenString or value.irc == True:
continue
# Send to this client if it's connected to the channel
if value.userID in recipients:
value.enqueue(packet)
else: else:
# USER # USER
# Make sure recipient user is connected # Make sure recipient user is connected
recipientToken = glob.tokens.getTokenFromUsername(to) recipientToken = glob.tokens.getTokenFromUsername(to)
if recipientToken == None: if recipientToken is None:
raise exceptions.userNotFoundException raise exceptions.userNotFoundException()
# Make sure the recipient is not a tournament client
#if recipientToken.tournament:
# raise exceptions.userTournamentException()
# Make sure the recipient is not restricted or we are FokaBot # Make sure the recipient is not restricted or we are FokaBot
if recipientToken.restricted == True and fro.lower() != "fokabot": if recipientToken.restricted and fro.lower() != glob.BOT_NAME.lower():
raise exceptions.userRestrictedException raise exceptions.userRestrictedException()
# TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend # TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend
# Away check
if recipientToken.awayCheck(token.userID):
sendMessage(to, fro, "\x01ACTION is away: {}\x01".format(recipientToken.awayMessage))
# Check message templates (mods/admins only) # Check message templates (mods/admins only)
if message in messageTemplates.templates and token.admin == True: if message in messageTemplates.templates and token.admin:
sendMessage(fro, to, messageTemplates.templates[message]) sendMessage(fro, to, messageTemplates.templates[message])
# Everything seems fine, send packet # Everything seems fine, send packet
recipientToken.enqueue(packet) recipientToken.enqueue(packet)
# Send the message to IRC # Send the message to IRC
if glob.irc == True and toIRC == True: if glob.irc and toIRC:
glob.ircServer.banchoMessage(fro, to, message) messageSplitInLines = message.encode("latin-1").decode("utf-8").split("\n")
for line in messageSplitInLines:
if line == messageSplitInLines[:1] and line == "":
continue
glob.ircServer.banchoMessage(fro, to, line)
# Spam protection (ignore FokaBot) # Spam protection (ignore FokaBot)
if userID > 999: if token.userID > 999:
token.spamProtection() token.spamProtection()
# Fokabot message # Fokabot message
if isChannel == True or to.lower() == "fokabot": if isChannel or to.lower() == glob.BOT_NAME.lower():
fokaMessage = fokabot.fokabotResponse(username, to, message) fokaMessage = fokabot.fokabotResponse(token.username, to, message)
if fokaMessage != False: if fokaMessage:
sendMessage("FokaBot", to if isChannel else fro, fokaMessage) sendMessage(glob.BOT_NAME, to if isChannel else fro, fokaMessage)
# File and discord logs (public chat only) # File and discord logs (public chat only)
if to.startswith("#") == True: if to.startswith("#") and not (message.startswith("\x01ACTION is playing") and to.startswith("#spect_")):
log.chat("{fro} @ {to}: {message}".format(fro=username, to=to, message=str(message.encode("utf-8")))) log.chat("{fro} @ {to}: {message}".format(fro=token.username, to=to, message=message.encode("latin-1").decode("utf-8")))
discordBotHelper.sendChatlog("**{fro} @ {to}:** {message}".format(fro=username, to=to, message=str(message.encode("utf-8"))[2:-1])) glob.schiavo.sendChatlog("**{fro} @ {to}:** {message}".format(fro=token.username, to=to, message=message.encode("latin-1").decode("utf-8")))
return 0 return 0
except exceptions.userSilencedException: except exceptions.userSilencedException:
token.enqueue(serverPackets.silenceEndTime(token.getSilenceSecondsLeft())) token.enqueue(serverPackets.silenceEndTime(token.getSilenceSecondsLeft()))
log.warning("{} tried to send a message during silence".format(username)) log.warning("{} tried to send a message during silence".format(token.username))
return 404 return 404
except exceptions.channelModeratedException: except exceptions.channelModeratedException:
log.warning("{} tried to send a message to a channel that is in moderated mode ({})".format(username, to)) log.warning("{} tried to send a message to a channel that is in moderated mode ({})".format(token.username, to))
return 404 return 404
except exceptions.channelUnknownException: except exceptions.channelUnknownException:
log.warning("{} tried to send a message to an unknown channel ({})".format(username, to)) log.warning("{} tried to send a message to an unknown channel ({})".format(token.username, to))
return 403 return 403
except exceptions.channelNoPermissionsException: except exceptions.channelNoPermissionsException:
log.warning("{} tried to send a message to channel {}, but they have no write permissions".format(username, to)) log.warning("{} tried to send a message to channel {}, but they have no write permissions".format(token.username, to))
return 404 return 404
except exceptions.userRestrictedException: except exceptions.userRestrictedException:
log.warning("{} tried to send a message {}, but the recipient is in restricted mode".format(username, to)) log.warning("{} tried to send a message {}, but the recipient is in restricted mode".format(token.username, to))
return 404
except exceptions.userTournamentException:
log.warning("{} tried to send a message {}, but the recipient is a tournament client".format(token.username, to))
return 404 return 404
except exceptions.userNotFoundException: except exceptions.userNotFoundException:
log.warning("User not connected to IRC/Bancho") log.warning("User not connected to IRC/Bancho")
return 401 return 401
except exceptions.invalidArgumentsException:
log.warning("{} tried to send an invalid message to {}".format(token.username, to))
return 404
""" IRC-Bancho Connect/Disconnect/Join/Part interfaces""" """ IRC-Bancho Connect/Disconnect/Join/Part interfaces"""
def fixUsernameForBancho(username):
"""
Convert username from IRC format (without spaces) to Bancho format (with spaces)
:param username: username to convert
:return: converted username
"""
# If there are no spaces or underscores in the name
# return it
if " " not in username and "_" not in username:
return username
# Exact match first
result = glob.db.fetch("SELECT id FROM users WHERE username = %s LIMIT 1", [username])
if result is not None:
return username
# Username not found, replace _ with space
return username.replace("_", " ")
def fixUsernameForIRC(username):
"""
Convert an username from Bancho format to IRC format (underscores instead of spaces)
:param username: username to convert
:return: converted username
"""
return username.replace(" ", "_")
def IRCConnect(username): def IRCConnect(username):
userID = userHelper.getID(username) """
if userID == False: Handle IRC login bancho-side.
Add token and broadcast login packet.
:param username: username
:return:
"""
userID = userUtils.getID(username)
if not userID:
log.warning("{} doesn't exist".format(username)) log.warning("{} doesn't exist".format(username))
return return
glob.tokens.deleteOldTokens(userID) glob.tokens.deleteOldTokens(userID)
glob.tokens.addToken(userID, irc=True) glob.tokens.addToken(userID, irc=True)
glob.tokens.enqueueAll(serverPackets.userPanel(userID)) glob.streams.broadcast("main", serverPackets.userPanel(userID))
log.info("{} logged in from IRC".format(username)) log.info("{} logged in from IRC".format(username))
def IRCDisconnect(username): def IRCDisconnect(username):
"""
Handle IRC logout bancho-side.
Remove token and broadcast logout packet.
:param username: username
:return:
"""
token = glob.tokens.getTokenFromUsername(username) token = glob.tokens.getTokenFromUsername(username)
if token == None: if token is None:
log.warning("{} doesn't exist".format(username)) log.warning("{} doesn't exist".format(username))
return return
logoutEvent.handle(token) logoutEvent.handle(token)
log.info("{} disconnected from IRC".format(username)) log.info("{} disconnected from IRC".format(username))
def IRCJoinChannel(username, channel): def IRCJoinChannel(username, channel):
userID = userHelper.getID(username) """
if userID == False: Handle IRC channel join bancho-side.
:param username: username
:param channel: channel name
:return: IRC return code
"""
userID = userUtils.getID(username)
if not userID:
log.warning("{} doesn't exist".format(username)) log.warning("{} doesn't exist".format(username))
return return
# NOTE: This should have also `toIRC` = False` tho, # NOTE: This should have also `toIRC` = False` tho,
@ -330,8 +404,30 @@ def IRCJoinChannel(username, channel):
return joinChannel(userID, channel) return joinChannel(userID, channel)
def IRCPartChannel(username, channel): def IRCPartChannel(username, channel):
userID = userHelper.getID(username) """
if userID == False: Handle IRC channel part bancho-side.
:param username: username
:param channel: channel name
:return: IRC return code
"""
userID = userUtils.getID(username)
if not userID:
log.warning("{} doesn't exist".format(username)) log.warning("{} doesn't exist".format(username))
return return
return partChannel(userID, channel) return partChannel(userID, channel)
def IRCAway(username, message):
"""
Handle IRC away command bancho-side.
:param username:
:param message: away message
:return: IRC return code
"""
userID = userUtils.getID(username)
if not userID:
log.warning("{} doesn't exist".format(username))
return
glob.tokens.getTokenFromUserID(userID).awayMessage = message
return 305 if message == "" else 306

View File

@ -2,26 +2,16 @@ import os
import configparser import configparser
class config: class config:
"""
config.ini object
config -- list with ini data
default -- if true, we have generated a default config.ini
"""
config = configparser.ConfigParser()
fileName = "" # config filename
default = True
# Check if config.ini exists and load/generate it # Check if config.ini exists and load/generate it
def __init__(self, __file): def __init__(self, file):
""" """
Initialize a config object Initialize a config file object
__file -- filename :param file: file name
""" """
self.config = configparser.ConfigParser()
self.fileName = __file self.default = True
self.fileName = file
if os.path.isfile(self.fileName): if os.path.isfile(self.fileName):
# config.ini found, load it # config.ini found, load it
self.config.read(self.fileName) self.config.read(self.fileName)
@ -35,11 +25,10 @@ class config:
# Check if config.ini has all needed the keys # Check if config.ini has all needed the keys
def checkConfig(self): def checkConfig(self):
""" """
Check if this config has the required keys Check is the config file has all required keys
return -- True if valid, False if not :return: True if valid, False if not valid
""" """
try: try:
# Try to get all the required keys # Try to get all the required keys
self.config.get("db","host") self.config.get("db","host")
@ -48,38 +37,54 @@ class config:
self.config.get("db","database") self.config.get("db","database")
self.config.get("db","workers") self.config.get("db","workers")
self.config.get("redis","host")
self.config.get("redis","port")
self.config.get("redis","database")
self.config.get("redis","password")
self.config.get("server","port") self.config.get("server","port")
self.config.get("server","threads")
self.config.get("server","gzip") self.config.get("server","gzip")
self.config.get("server","gziplevel") self.config.get("server","gziplevel")
self.config.get("server","cikey") self.config.get("server","cikey")
self.config.get("server","cloudflare")
self.config.get("cheesegull", "apiurl")
self.config.get("cheesegull", "apikey")
self.config.get("debug","enable") self.config.get("debug","enable")
self.config.get("debug","packets") self.config.get("debug","packets")
self.config.get("debug","time") self.config.get("debug","time")
self.config.get("sentry","enable") self.config.get("sentry","enable")
self.config.get("sentry","banchodns") self.config.get("sentry","banchodsn")
self.config.get("sentry","ircdns") self.config.get("sentry","ircdsn")
self.config.get("discord","enable") self.config.get("discord","enable")
self.config.get("discord","boturl") self.config.get("discord","boturl")
self.config.get("discord","devgroup") self.config.get("discord","devgroup")
self.config.get("datadog", "enable")
self.config.get("datadog", "apikey")
self.config.get("datadog", "appkey")
self.config.get("irc","enable") self.config.get("irc","enable")
self.config.get("irc","port") self.config.get("irc","port")
self.config.get("irc","hostname")
self.config.get("localize","enable") self.config.get("localize","enable")
self.config.get("localize","ipapiurl") self.config.get("localize","ipapiurl")
self.config.get("custom", "config")
return True return True
except: except configparser.Error:
return False return False
# Generate a default config.ini
def generateDefaultConfig(self): def generateDefaultConfig(self):
"""Open and set default keys for that config file""" """
Write a default config file to disk
:return:
"""
# Open config.ini in write mode # Open config.ini in write mode
f = open(self.fileName, "w") f = open(self.fileName, "w")
@ -91,12 +96,22 @@ class config:
self.config.set("db", "database", "ripple") self.config.set("db", "database", "ripple")
self.config.set("db", "workers", "4") self.config.set("db", "workers", "4")
self.config.add_section("redis")
self.config.set("redis", "host", "localhost")
self.config.set("redis", "port", "6379")
self.config.set("redis", "database", "0")
self.config.set("redis", "password", "")
self.config.add_section("server") self.config.add_section("server")
self.config.set("server", "port", "5001") self.config.set("server", "port", "5001")
self.config.set("server", "threads", "16")
self.config.set("server", "gzip", "1") self.config.set("server", "gzip", "1")
self.config.set("server", "gziplevel", "6") self.config.set("server", "gziplevel", "6")
self.config.set("server", "cikey", "changeme") self.config.set("server", "cikey", "changeme")
self.config.set("server", "cloudflare", "0")
self.config.add_section("cheesegull")
self.config.set("cheesegull", "apiurl", "http://cheesegu.ll/api")
self.config.set("cheesegull", "apikey", "")
self.config.add_section("debug") self.config.add_section("debug")
self.config.set("debug", "enable", "0") self.config.set("debug", "enable", "0")
@ -105,22 +120,31 @@ class config:
self.config.add_section("sentry") self.config.add_section("sentry")
self.config.set("sentry", "enable", "0") self.config.set("sentry", "enable", "0")
self.config.set("sentry", "banchodns", "") self.config.set("sentry", "banchodsn", "")
self.config.set("sentry", "ircdns", "") self.config.set("sentry", "ircdsn", "")
self.config.add_section("discord") self.config.add_section("discord")
self.config.set("discord", "enable", "0") self.config.set("discord", "enable", "0")
self.config.set("discord", "boturl", "") self.config.set("discord", "boturl", "")
self.config.set("discord", "devgroup", "") self.config.set("discord", "devgroup", "")
self.config.add_section("datadog")
self.config.set("datadog", "enable", "0")
self.config.set("datadog", "apikey", "")
self.config.set("datadog", "appkey", "")
self.config.add_section("irc") self.config.add_section("irc")
self.config.set("irc", "enable", "1") self.config.set("irc", "enable", "1")
self.config.set("irc", "port", "6667") self.config.set("irc", "port", "6667")
self.config.set("irc", "hostname", "ripple")
self.config.add_section("localize") self.config.add_section("localize")
self.config.set("localize", "enable", "1") self.config.set("localize", "enable", "1")
self.config.set("localize", "ipapiurl", "http://ip.zxq.co") self.config.set("localize", "ipapiurl", "http://ip.zxq.co")
self.config.add_section("custom")
self.config.set("custom", "config", "common/config.json")
# Write ini to file and close # Write ini to file and close
self.config.write(f) self.config.write(f)
f.close() f.close()

View File

@ -1,14 +1,14 @@
"""Some console related functions""" from common.constants import bcolors
from constants import bcolors
from objects import glob from objects import glob
def printServerStartHeader(asciiArt): def printServerStartHeader(asciiArt=True):
"""Print server start header with optional ascii art """
Print server start message
asciiArt -- if True, will print ascii art too""" :param asciiArt: print BanchoBoat ascii art. Default: True
:return:
if asciiArt == True: """
if asciiArt:
print("{} _ __".format(bcolors.GREEN)) print("{} _ __".format(bcolors.GREEN))
print(" (_) / /") print(" (_) / /")
print(" ______ __ ____ ____ / /____") print(" ______ __ ____ ____ / /____")
@ -27,45 +27,52 @@ def printServerStartHeader(asciiArt):
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^{}".format(bcolors.ENDC)) print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^{}".format(bcolors.ENDC))
printColored("> Welcome to pep.py osu!bancho server v{}".format(glob.VERSION), bcolors.GREEN) printColored("> Welcome to pep.py osu!bancho server v{}".format(glob.VERSION), bcolors.GREEN)
printColored("> Common submodule v{}".format(glob.COMMON_VERSION), bcolors.GREEN)
printColored("> Made by the Ripple team", bcolors.GREEN) printColored("> Made by the Ripple team", bcolors.GREEN)
printColored("> {}https://github.com/osuripple/ripple".format(bcolors.UNDERLINE), bcolors.GREEN) printColored("> {}https://zxq.co/ripple/pep.py".format(bcolors.UNDERLINE), bcolors.GREEN)
printColored("> Press CTRL+C to exit\n",bcolors.GREEN) printColored("> Custom branch by the osufx team (just Sunpy)", bcolors.GREEN)
printColored("> {}https://github.com/osufx/pep.py".format(bcolors.UNDERLINE), bcolors.GREEN)
printColored("> Press CTRL+C to exit\n", bcolors.GREEN)
def printNoNl(string): def printNoNl(string):
""" """
Print string without new line at the end Print a string without \n at the end
string -- string to print :param string: string to print
:return:
""" """
print(string, end="") print(string, end="")
def printColored(string, color): def printColored(string, color):
""" """
Print colored string Print a colored string
string -- string to print :param string: string to print
color -- see bcolors.py :param color: ANSI color code
:return:
""" """
print("{}{}{}".format(color, string, bcolors.ENDC)) print("{}{}{}".format(color, string, bcolors.ENDC))
def printError(): def printError():
"""Print error text FOR LOADING""" """
Print a red "Error"
:return:
"""
printColored("Error", bcolors.RED) printColored("Error", bcolors.RED)
def printDone(): def printDone():
"""Print error text FOR LOADING""" """
Print a green "Done"
:return:
"""
printColored("Done", bcolors.GREEN) printColored("Done", bcolors.GREEN)
def printWarning(): def printWarning():
"""Print error text FOR LOADING""" """
Print a yellow "Warning"
:return:
"""
printColored("Warning", bcolors.YELLOW) printColored("Warning", bcolors.YELLOW)

View File

@ -1,5 +1,4 @@
"""Contains all country codes with their osu numeric code""" # TODO: Update countries list
countryCodes = { countryCodes = {
"LV": 132, "LV": 132,
"AD": 3, "AD": 3,
@ -253,15 +252,13 @@ countryCodes = {
"AI": 7 "AI": 7
} }
def getCountryID(code): def getCountryID(code):
""" """
Get country ID for osu client Get osu country ID from country letters
code -- country name abbreviation (eg: US) :param code: country letters (eg: US)
return -- country code int :return: country osu code
""" """
if code in countryCodes: if code in countryCodes:
return countryCodes[code] return countryCodes[code]
else: else:
@ -271,10 +268,9 @@ def getCountryLetters(code):
""" """
Get country letters from osu country ID Get country letters from osu country ID
code -- country code int :param code: osu country ID
return -- country name (2 letters) (XX if code not found) :return: country letters (XX if not found)
""" """
for key, value in countryCodes.items(): for key, value in countryCodes.items():
if value == code: if value == code:
return key return key

View File

@ -1,138 +0,0 @@
import pymysql
from constants import bcolors
from helpers import consoleHelper
import threading
from objects import glob
class db:
"""A MySQL database connection"""
connection = None
disconnected = False
pingTime = 600
def __init__(self, __host, __username, __password, __database, __pingTime = 600):
"""
Connect to MySQL database
__host -- MySQL host name
__username -- MySQL username
__password -- MySQL password
__database -- MySQL database name
__pingTime -- MySQL database ping time (default: 600)
"""
self.connection = pymysql.connect(host=__host, user=__username, password=__password, db=__database, cursorclass=pymysql.cursors.DictCursor, autocommit=True)
self.pingTime = __pingTime
self.pingLoop()
def bindParams(self, __query, __params):
"""
Replace every ? with the respective **escaped** parameter in array
__query -- query with ?s
__params -- array with params
return -- new query
"""
for i in __params:
escaped = self.connection.escape(i)
__query = __query.replace("?", str(escaped), 1)
return __query
def execute(self, __query, __params = None):
"""
Execute a SQL query
__query -- query, can contain ?s
__params -- array with params. Optional
"""
log.debug(query)
with self.connection.cursor() as cursor:
try:
# Bind params if needed
if __params != None:
__query = self.bindParams(__query, __params)
# Execute the query
cursor.execute(__query)
finally:
# Close this connection
cursor.close()
def fetch(self, __query, __params = None, __all = False):
"""
Fetch the first (or all) element(s) of SQL query result
__query -- query, can contain ?s
__params -- array with params. Optional
__all -- if true, will fetch all values. Same as fetchAll
return -- dictionary with result data or False if failed
"""
log.debug(query)
with self.connection.cursor() as cursor:
try:
# Bind params if needed
if __params != None:
__query = self.bindParams(__query, __params)
# Execute the query with binded params
cursor.execute(__query)
# Get first result and return it
if __all == False:
return cursor.fetchone()
else:
return cursor.fetchall()
finally:
# Close this connection
cursor.close()
def fetchAll(self, __query, __params = None):
"""
Fetch the all elements of SQL query result
__query -- query, can contain ?s
__params -- array with params. Optional
return -- dictionary with result data
"""
return self.fetch(__query, __params, True)
def pingLoop(self):
"""
Pings MySQL server. We need to ping/execute a query at least once every 8 hours
or the connection will die.
If called once, will recall after 30 minutes and so on, forever
CALL THIS FUNCTION ONLY ONCE!
"""
# Default loop time
time = self.pingTime
# Make sure the connection is alive
try:
# Try to ping and reconnect if not connected
self.connection.ping()
if self.disconnected == True:
# If we were disconnected, set disconnected to false and print message
self.disconnected = False
log.error("> Reconnected to MySQL server!", bcolors.GREEN)
except:
# Can't ping MySQL server. Show error and call loop in 5 seconds
log.error("[!] CRITICAL!! MySQL connection died! Make sure your MySQL server is running! Checking again in 5 seconds...", bcolors.RED)
self.disconnected = True
time = 5
# Schedule a new check (endless loop)
threading.Timer(time, self.pingLoop).start()

View File

@ -1,121 +0,0 @@
import MySQLdb
import threading
from helpers import logHelper as log
class mysqlWorker:
"""
Instance of a pettirosso meme
"""
def __init__(self, wid, host, username, password, database):
"""
Create a pettirosso meme (mysql worker)
wid -- worker id
host -- hostname
username -- MySQL username
password -- MySQL password
database -- MySQL database name
"""
self.wid = wid
self.connection = MySQLdb.connect(host, username, password, database)
self.connection.autocommit(True)
self.ready = True
self.lock = threading.Lock()
class db:
"""
A MySQL db connection with multiple workers
"""
def __init__(self, host, username, password, database, workers):
"""
Create MySQL workers aka pettirossi meme
host -- hostname
username -- MySQL username
password -- MySQL password
database -- MySQL database name
workers -- Number of workers to spawn
"""
#self.lock = threading.Lock()
#self.connection = MySQLdb.connect(host, username, password, database)
self.workers = []
self.lastWorker = 0
self.workersNumber = workers
for i in range(0,self.workersNumber):
print(".", end="")
self.workers.append(mysqlWorker(i, host, username, password, database))
def getWorker(self):
"""
Return a worker object (round-robin way)
return -- worker object
"""
if self.lastWorker >= self.workersNumber-1:
self.lastWorker = 0
else:
self.lastWorker += 1
#print("Using worker {}".format(self.lastWorker))
return self.workers[self.lastWorker]
def execute(self, query, params = ()):
"""
Executes a query
query -- Query to execute. You can bind parameters with %s
params -- Parameters list. First element replaces first %s and so on. Optional.
"""
log.debug(query)
# Get a worker and acquire its lock
worker = self.getWorker()
worker.lock.acquire()
try:
# Create cursor, execute query and commit
cursor = worker.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute(query, params)
return cursor.lastrowid
finally:
# Close the cursor and release worker's lock
if cursor:
cursor.close()
worker.lock.release()
def fetch(self, query, params = (), all = False):
"""
Fetch a single value from db that matches given query
query -- Query to execute. You can bind parameters with %s
params -- Parameters list. First element replaces first %s and so on. Optional.
all -- Fetch one or all values. Used internally. Use fetchAll if you want to fetch all values.
"""
log.debug(query)
# Get a worker and acquire its lock
worker = self.getWorker()
worker.lock.acquire()
try:
# Create cursor, execute the query and fetch one/all result(s)
cursor = worker.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute(query, params)
if all == True:
return cursor.fetchall()
else:
return cursor.fetchone()
finally:
# Close the cursor and release worker's lock
if cursor:
cursor.close()
worker.lock.release()
def fetchAll(self, query, params = ()):
"""
Fetch all values from db that matche given query.
Calls self.fetch with all = True.
query -- Query to execute. You can bind parameters with %s
params -- Parameters list. First element replaces first %s and so on. Optional.
"""
return self.fetch(query, params, True)

View File

@ -1,69 +0,0 @@
import requests
from objects import glob
from helpers import generalFunctions
from urllib.parse import urlencode
from helpers import consoleHelper
from constants import bcolors
def sendDiscordMessage(channel, message, alertDev = False, prefix = "**pep.py**"):
"""
Send a message to a discord server.
This is used with ripple's schiavobot.
channel -- bunk, staff or general
message -- message to send
alertDev -- if True, hl developers group
prefix -- string to prepend to message
"""
if glob.discord == True:
for _ in range(0,20):
try:
finalMsg = "{prefix} {message}".format(prefix=prefix, message=message) if alertDev == False else "{prefix} {hl} - {message}".format(prefix=prefix, hl=glob.conf.config["discord"]["devgroup"], message=message)
requests.get("{}/{}?{}".format(glob.conf.config["discord"]["boturl"], channel, urlencode({ "message": finalMsg })))
break
except:
continue
def sendConfidential(message, alertDev = False):
"""
Send a message to #bunker
message -- message to send
"""
sendDiscordMessage("bunk", message, alertDev)
def sendStaff(message):
"""
Send a message to #staff
message -- message to send
"""
sendDiscordMessage("staff", message)
def sendGeneral(message):
"""
Send a message to #general
message -- message to send
"""
sendDiscordMessage("general", message)
def sendChatlog(message):
"""
Send a message to #chatlog
message -- message to send
"""
sendDiscordMessage("chatlog", message, prefix="")
def sendCM(message):
"""
Send a message to #communitymanagers
message -- message to send
"""
sendDiscordMessage("cm", message)

View File

@ -1,128 +0,0 @@
"""Some functions that don't fit in any other file"""
from constants import mods
from time import gmtime, strftime
def stringToBool(s):
"""
Convert a string (True/true/1) to bool
s -- string/int value
return -- True/False
"""
return (s == "True" or s== "true" or s == "1" or s == 1)
def hexString(s):
"""
Output s' bytes in HEX
s -- string
return -- string with hex value
"""
return ":".join("{:02x}".format(ord(str(c))) for c in s)
def readableMods(__mods):
"""
Return a string with readable std mods.
Used to convert a mods number for oppai
__mods -- mods bitwise number
return -- readable mods string, eg HDDT
"""
r = ""
if __mods == 0:
return r
if __mods & mods.NoFail > 0:
r += "NF"
if __mods & mods.Easy > 0:
r += "EZ"
if __mods & mods.Hidden > 0:
r += "HD"
if __mods & mods.HardRock > 0:
r += "HR"
if __mods & mods.DoubleTime > 0:
r += "DT"
if __mods & mods.HalfTime > 0:
r += "HT"
if __mods & mods.Flashlight > 0:
r += "FL"
if __mods & mods.SpunOut > 0:
r += "SO"
return r
def getRank(gameMode, __mods, acc, c300, c100, c50, cmiss):
"""
Return a string with rank/grade for a given score.
Used mainly for "tillerino"
gameMode -- mode (0 = osu!, 1 = Taiko, 2 = CtB, 3 = osu!mania)
__mods -- mods bitwise number
acc -- accuracy
c300 -- 300 hit count
c100 -- 100 hit count
c50 -- 50 hit count
cmiss -- miss count
return -- rank/grade string
"""
total = c300 + c100 + c50 + cmiss
hdfl = (__mods & (mods.Hidden | mods.Flashlight | mods.FadeIn)) > 0
ss = "sshd" if hdfl else "ss"
s = "shd" if hdfl else "s"
if gameMode == 0 or gameMode == 1:
# osu!std / taiko
ratio300 = c300 / total
ratio50 = c50 / total
if ratio300 == 1:
return ss
if ratio300 > 0.9 and ratio50 <= 0.01 and cmiss == 0:
return s
if (ratio300 > 0.8 and cmiss == 0) or (ratio300 > 0.9):
return "a"
if (ratio300 > 0.7 and cmiss == 0) or (ratio300 > 0.8):
return "b"
if ratio300 > 0.6:
return "c"
return "d"
elif gameMode == 2:
# CtB
if acc == 100:
return ss
if acc > 98:
return s
if acc > 94:
return "a"
if acc > 90:
return "b"
if acc > 85:
return "c"
return "d"
elif gameMode == 3:
# osu!mania
if acc == 100:
return ss
if acc > 95:
return s
if acc > 90:
return "a"
if acc > 80:
return "b"
if acc > 70:
return "c"
return "d"
return "a"
def strContains(s, w):
return (' ' + w + ' ') in (' ' + s + ' ')
def getTimestamp():
"""
Return current time in YYYY-MM-DD HH:MM:SS format.
Used in logs.
"""
return strftime("%Y-%m-%d %H:%M:%S", gmtime())

View File

@ -1,17 +1,17 @@
import urllib.request
import json import json
import urllib.request
from common.log import logUtils as log
from objects import glob from objects import glob
from helpers import logHelper as log
def getCountry(ip): def getCountry(ip):
""" """
Get country from IP address Get country from IP address using geoip api
ip -- IP Address :param ip: IP address
return -- Country code (2 letters) :return: country code. XX if invalid.
""" """
try: try:
# Try to get country from Pikolo Aul's Go-Sanic ip API # Try to get country from Pikolo Aul's Go-Sanic ip API
result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["country"] result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["country"]
@ -20,19 +20,17 @@ def getCountry(ip):
log.error("Error in get country") log.error("Error in get country")
return "XX" return "XX"
def getLocation(ip): def getLocation(ip):
""" """
Get latitude and longitude from IP address Get latitude and longitude from IP address using geoip api
ip -- IP address :param ip: IP address
return -- [latitude, longitude] :return: (latitude, longitude)
""" """
try: try:
# Try to get position from Pikolo Aul's Go-Sanic ip API # Try to get position from Pikolo Aul's Go-Sanic ip API
result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["loc"].split(",") result = json.loads(urllib.request.urlopen("{}/{}".format(glob.conf.config["localize"]["ipapiurl"], ip), timeout=3).read().decode())["loc"].split(",")
return [float(result[0]), float(result[1])] return float(result[0]), float(result[1])
except: except:
log.error("Error in get position") log.error("Error in get position")
return [0,0] return 0, 0

View File

@ -1,140 +0,0 @@
from constants import bcolors
from helpers import discordBotHelper
from helpers import generalFunctions
from objects import glob
from helpers import userHelper
import time
import os
ENDL = "\n" if os.name == "posix" else "\r\n"
def logMessage(message, alertType = "INFO", messageColor = bcolors.ENDC, discord = None, alertDev = False, of = None, stdout = True):
"""
Logs a message to stdout/discord/file
message -- message to log
alertType -- can be any string. Standard types: INFO, WARNING and ERRORS. Defalt: INFO
messageColor -- message color (see constants.bcolors). Default = bcolots.ENDC (no color)
discord -- discord channel (bunker/cm/staff/general). Optional. Default = None
alertDev -- if True, devs will receive an hl on discord. Default: False
of -- if not None but a string, log the message to that file (inside .data folder). Eg: "warnings.txt" Default: None (don't log to file)
stdout -- if True, print the message to stdout. Default: True
"""
# Get type color from alertType
if alertType == "INFO":
typeColor = bcolors.GREEN
elif alertType == "WARNING":
typeColor = bcolors.YELLOW
elif alertType == "ERROR":
typeColor = bcolors.RED
elif alertType == "CHAT":
typeColor = bcolors.BLUE
elif alertType == "DEBUG":
typeColor = bcolors.PINK
else:
typeColor = bcolors.ENDC
# Message without colors
finalMessage = "[{time}] {type} - {message}".format(time=generalFunctions.getTimestamp(), type=alertType, message=message)
# Message with colors
finalMessageConsole = "{typeColor}[{time}] {type}{endc} - {messageColor}{message}{endc}".format(
time=generalFunctions.getTimestamp(),
type=alertType,
message=message,
typeColor=typeColor,
messageColor=messageColor,
endc=bcolors.ENDC)
# Log to console
if stdout == True:
print(finalMessageConsole)
# Log to discord if needed
if discord != None:
if discord == "bunker":
discordBotHelper.sendConfidential(message, alertDev)
elif discord == "cm":
discordBotHelper.sendCM(message)
elif discord == "staff":
discordBotHelper.sendStaff(message)
elif discord == "general":
discordBotHelper.sendGeneral(message)
# Log to file if needed
if of != None:
try:
glob.fLocks.lockFile(of)
with open(".data/{}".format(of), "a") as f:
f.write(finalMessage+ENDL)
finally:
glob.fLocks.unlockFile(of)
def warning(message, discord = None, alertDev = False):
"""
Log a warning to stdout, warnings.log (always) and discord (optional)
message -- warning message
discord -- if not None, send message to that discord channel through schiavo. Optional. Default = None
alertDev -- if True, send al hl to devs on discord. Optional. Default = False.
"""
logMessage(message, "WARNING", bcolors.YELLOW, discord, alertDev, "warnings.txt")
def error(message, discord = None, alertDev = True):
"""
Log an error to stdout, errors.log (always) and discord (optional)
message -- error message
discord -- if not None, send message to that discord channel through schiavo. Optional. Default = None
alertDev -- if True, send al hl to devs on discord. Optional. Default = False.
"""
logMessage(message, "ERROR", bcolors.RED, discord, alertDev, "errors.txt")
def info(message, discord = None, alertDev = False):
"""
Log an error to stdout (and info.log)
message -- info message
discord -- if not None, send message to that discord channel through schiavo. Optional. Default = None
alertDev -- if True, send al hl to devs on discord. Optional. Default = False.
"""
logMessage(message, "INFO", bcolors.ENDC, discord, alertDev, "info.txt")
def debug(message):
"""
Log a debug message to stdout and debug.log if server is running in debug mode
message -- debug message
"""
if glob.debug == True:
logMessage(message, "DEBUG", bcolors.PINK, of="debug.txt")
def chat(message):
"""
Log public messages to stdout and chatlog_public.txt
message -- chat message
"""
logMessage(message, "CHAT", bcolors.BLUE, of="chatlog_public.txt")
def pm(message):
"""
Log private messages to stdout and chatlog_private.txt
message -- chat message
"""
logMessage(message, "CHAT", bcolors.BLUE, of="chatlog_private.txt")
def rap(userID, message, discord=False, through="FokaBot"):
"""
Log a private message to Admin logs
userID -- userID of who made the action
message -- message without subject (eg: "is a meme" becomes "user is a meme")
discord -- if True, send message to discord
through -- "through" thing string. Optional. Default: "FokaBot"
"""
glob.db.execute("INSERT INTO rap_logs (id, userid, text, datetime, through) VALUES (NULL, %s, %s, %s, %s)", [userID, message, int(time.time()), through])
if discord == True:
username = userHelper.getUsername(userID)
logMessage("{} {}".format(username, message), discord=True)

View File

@ -1,272 +0,0 @@
import struct
from constants import dataTypes
def uleb128Encode(num):
"""
Encode int -> uleb128
num -- int to encode
return -- bytearray with encoded number
"""
arr = bytearray()
length = 0
if num == 0:
return bytearray(b"\x00")
while num > 0:
arr.append(num & 127)
num = num >> 7
if num != 0:
arr[length] = arr[length] | 128
length+=1
return arr
def uleb128Decode(num):
"""
Decode uleb128 -> int
num -- encoded uleb128
return -- list. [total, length]
"""
shift = 0
arr = [0,0] #total, length
while True:
b = num[arr[1]]
arr[1]+=1
arr[0] = arr[0] | (int(b & 127) << shift)
if b & 128 == 0:
break
shift += 7
return arr
def unpackData(__data, __dataType):
"""
Unpacks data according to dataType
__data -- bytes array to unpack
__dataType -- data type. See dataTypes.py
return -- unpacked bytes
"""
# Get right pack Type
if __dataType == dataTypes.uInt16:
unpackType = "<H"
elif __dataType == dataTypes.sInt16:
unpackType = "<h"
elif __dataType == dataTypes.uInt32:
unpackType = "<L"
elif __dataType == dataTypes.sInt32:
unpackType = "<l"
elif __dataType == dataTypes.uInt64:
unpackType = "<Q"
elif __dataType == dataTypes.sInt64:
unpackType = "<q"
elif __dataType == dataTypes.string:
unpackType = "<s"
elif __dataType == dataTypes.ffloat:
unpackType = "<f"
else:
unpackType = "<B"
# Unpack
return struct.unpack(unpackType, bytes(__data))[0]
def packData(__data, __dataType):
"""
Packs data according to dataType
data -- bytes to pack
dataType -- data type. See dataTypes.py
return -- packed bytes
"""
data = bytes() # data to return
pack = True # if True, use pack. False only with strings
# Get right pack Type
if __dataType == dataTypes.bbytes:
# Bytes, do not use pack, do manually
pack = False
data = __data
elif __dataType == dataTypes.intList:
# Pack manually
pack = False
# Add length
data = packData(len(__data), dataTypes.uInt16)
# Add all elements
for i in __data:
data += packData(i, dataTypes.sInt32)
elif __dataType == dataTypes.string:
# String, do not use pack, do manually
pack = False
if len(__data) == 0:
# Empty string
data += b"\x00"
else:
# Non empty string
data += b"\x0B"
data += uleb128Encode(len(__data))
data += str.encode(__data, "latin_1", "ignore")
elif __dataType == dataTypes.uInt16:
packType = "<H"
elif __dataType == dataTypes.sInt16:
packType = "<h"
elif __dataType == dataTypes.uInt32:
packType = "<L"
elif __dataType == dataTypes.sInt32:
packType = "<l"
elif __dataType == dataTypes.uInt64:
packType = "<Q"
elif __dataType == dataTypes.sInt64:
packType = "<q"
elif __dataType == dataTypes.string:
packType = "<s"
elif __dataType == dataTypes.ffloat:
packType = "<f"
else:
packType = "<B"
# Pack if needed
if pack == True:
data += struct.pack(packType, __data)
return data
# TODO: Wat dangerous
def buildPacket(__packet, __packetData = []):
"""
Build a packet
packet -- packet id (int)
packetData -- list [[data, dataType], [data, dataType], ...]
return -- packet bytes
"""
# Set some variables
packetData = bytes()
packetLength = 0
packetBytes = bytes()
# Pack packet data
for i in __packetData:
packetData += packData(i[0], i[1])
# Set packet length
packetLength = len(packetData)
# Return packet as bytes
packetBytes += struct.pack("<h", __packet) # packet id (int16)
packetBytes += bytes(b"\x00") # unused byte
packetBytes += struct.pack("<l", packetLength) # packet lenght (iint32)
packetBytes += packetData # packet data
return packetBytes
def readPacketID(stream):
"""
Read packetID from stream (0-1 bytes)
stream -- data stream
return -- packet ID (int)
"""
return unpackData(stream[0:2], dataTypes.uInt16)
def readPacketLength(stream):
"""
Read packet length from stream (3-4-5-6 bytes)
stream -- data stream
return -- packet length (int)
"""
return unpackData(stream[3:7], dataTypes.uInt32)
def readPacketData(stream, structure = [], hasFirstBytes = True):
"""
Read packet data from stream according to structure
stream -- data stream
structure -- [[name, dataType], [name, dataType], ...]
hasFirstBytes -- if True, stream has packetID and length bytes.
if False, stream has only packetData.
Optional. Default: True
return -- dictionary. key: name, value: read data
"""
# Read packet ID (first 2 bytes)
data = {}
# Skip packet ID and packet length if needed
if hasFirstBytes == True:
end = 7
start = 7
else:
end = 0
start = 0
# Read packet
for i in structure:
start = end
unpack = True
if i[1] == dataTypes.intList:
# sInt32 list.
# Unpack manually with for loop
unpack = False
# Read length (uInt16)
length = unpackData(stream[start:start+2], dataTypes.uInt16)
# Read all int inside list
data[i[0]] = []
for j in range(0,length):
data[i[0]].append(unpackData(stream[start+2+(4*j):start+2+(4*(j+1))], dataTypes.sInt32))
# Update end
end = start+2+(4*length)
elif i[1] == dataTypes.string:
# String, don't unpack
unpack = False
# Check empty string
if stream[start] == 0:
# Empty string
data[i[0]] = ""
end = start+1
else:
# Non empty string
# Read length and calculate end
length = uleb128Decode(stream[start+1:])
end = start+length[0]+length[1]+1
# Read bytes
data[i[0]] = ''.join(chr(j) for j in stream[start+1+length[1]:end])
elif i[1] == dataTypes.byte:
end = start+1
elif i[1] == dataTypes.uInt16 or i[1] == dataTypes.sInt16:
end = start+2
elif i[1] == dataTypes.uInt32 or i[1] == dataTypes.sInt32:
end = start+4
elif i[1] == dataTypes.uInt64 or i[1] == dataTypes.sInt64:
end = start+8
# Unpack if needed
if unpack == True:
data[i[0]] = unpackData(stream[start:end], i[1])
return data

268
helpers/packetHelper.pyx Normal file
View File

@ -0,0 +1,268 @@
import struct
from constants import dataTypes
cpdef bytearray uleb128Encode(int num):
"""
Encode an int to uleb128
:param num: int to encode
:return: bytearray with encoded number
"""
cdef bytearray arr = bytearray()
cdef int length = 0
if num == 0:
return bytearray(b"\x00")
while num > 0:
arr.append(num & 127)
num >>= 7
if num != 0:
arr[length] |= 128
length+=1
return arr
cpdef list uleb128Decode(bytes num):
"""
Decode a uleb128 to int
:param num: encoded uleb128 int
:return: (total, length)
"""
cdef int shift = 0
cdef list arr = [0,0] #total, length
cdef int b
while True:
b = num[arr[1]]
arr[1]+=1
arr[0] |= int(b & 127) << shift
if b & 128 == 0:
break
shift += 7
return arr
cpdef unpackData(bytes data, int dataType):
"""
Unpacks a single section of a packet.
:param data: bytes to unpack
:param dataType: data type
:return: unpacked bytes
"""
# Get right pack Type
if dataType == dataTypes.UINT16:
unpackType = "<H"
elif dataType == dataTypes.SINT16:
unpackType = "<h"
elif dataType == dataTypes.UINT32:
unpackType = "<L"
elif dataType == dataTypes.SINT32:
unpackType = "<l"
elif dataType == dataTypes.UINT64:
unpackType = "<Q"
elif dataType == dataTypes.SINT64:
unpackType = "<q"
elif dataType == dataTypes.STRING:
unpackType = "<s"
elif dataType == dataTypes.FFLOAT:
unpackType = "<f"
else:
unpackType = "<B"
# Unpack
return struct.unpack(unpackType, bytes(data))[0]
cpdef bytes packData(__data, int dataType):
"""
Packs a single section of a packet.
:param __data: data to pack
:param dataType: data type
:return: packed bytes
"""
cdef bytes data = bytes() # data to return
cdef bint pack = True # if True, use pack. False only with strings
cdef str packType
# Get right pack Type
if dataType == dataTypes.BBYTES:
# Bytes, do not use pack, do manually
pack = False
data = __data
elif dataType == dataTypes.INT_LIST:
# Pack manually
pack = False
# Add length
data = packData(len(__data), dataTypes.UINT16)
# Add all elements
for i in __data:
data += packData(i, dataTypes.SINT32)
elif dataType == dataTypes.STRING:
# String, do not use pack, do manually
pack = False
if len(__data) == 0:
# Empty string
data += b"\x00"
else:
# Non empty string
data += b"\x0B"
data += uleb128Encode(len(__data))
data += str.encode(__data, "latin_1", "ignore")
elif dataType == dataTypes.UINT16:
packType = "<H"
elif dataType == dataTypes.SINT16:
packType = "<h"
elif dataType == dataTypes.UINT32:
packType = "<L"
elif dataType == dataTypes.SINT32:
packType = "<l"
elif dataType == dataTypes.UINT64:
packType = "<Q"
elif dataType == dataTypes.SINT64:
packType = "<q"
elif dataType == dataTypes.STRING:
packType = "<s"
elif dataType == dataTypes.FFLOAT:
packType = "<f"
else:
packType = "<B"
# Pack if needed
if pack:
data += struct.pack(packType, __data)
return data
cpdef bytes buildPacket(int __packet, list __packetData = None):
"""
Builds a packet
:param __packet: packet ID
:param __packetData: packet structure [[data, dataType], [data, dataType], ...]
:return: packet bytes
"""
# Default argument
if __packetData is None:
__packetData = []
# Set some variables
cdef bytes packetData = bytes()
cdef int packetLength = 0
cdef bytes packetBytes = bytes()
# Pack packet data
cdef list i
for i in __packetData:
packetData += packData(i[0], i[1])
# Set packet length
packetLength = len(packetData)
# Return packet as bytes
packetBytes += struct.pack("<h", __packet) # packet id (int16)
packetBytes += bytes(b"\x00") # unused byte
packetBytes += struct.pack("<l", packetLength) # packet lenght (iint32)
packetBytes += packetData # packet data
return packetBytes
cpdef int readPacketID(bytes stream):
"""
Read packetID (first two bytes) from a packet
:param stream: packet bytes
:return: packet ID
"""
return unpackData(stream[0:2], dataTypes.UINT16)
cpdef int readPacketLength(bytes stream):
"""
Read packet data length (3:7 bytes) from a packet
:param stream: packet bytes
:return: packet data length
"""
return unpackData(stream[3:7], dataTypes.UINT32)
cpdef readPacketData(bytes stream, list structure=None, bint hasFirstBytes = True):
"""
Read packet data from `stream` according to `structure`
:param stream: packet bytes
:param structure: packet structure: [[name, dataType], [name, dataType], ...]
:param hasFirstBytes: if True, `stream` has packetID and length bytes.
if False, `stream` has only packet data. Default: True
:return: {name: unpackedValue, ...}
"""
# Default list argument
if structure is None:
structure = []
# Read packet ID (first 2 bytes)
cdef dict data = {}
# Skip packet ID and packet length if needed
cdef start, end
if hasFirstBytes:
end = 7
start = 7
else:
end = 0
start = 0
# Read packet
cdef list i
cdef bint unpack
for i in structure:
start = end
unpack = True
if i[1] == dataTypes.INT_LIST:
# sInt32 list.
# Unpack manually with for loop
unpack = False
# Read length (uInt16)
length = unpackData(stream[start:start+2], dataTypes.UINT16)
# Read all int inside list
data[i[0]] = []
for j in range(0,length):
data[i[0]].append(unpackData(stream[start+2+(4*j):start+2+(4*(j+1))], dataTypes.SINT32))
# Update end
end = start+2+(4*length)
elif i[1] == dataTypes.STRING:
# String, don't unpack
unpack = False
# Check empty string
if stream[start] == 0:
# Empty string
data[i[0]] = ""
end = start+1
else:
# Non empty string
# Read length and calculate end
length = uleb128Decode(stream[start+1:])
end = start+length[0]+length[1]+1
# Read bytes
#data[i[0]] = ''.join(chr(j) for j in stream[start+1+length[1]:end])
data[i[0]] = ""
for j in stream[start+1+length[1]:end]:
data[i[0]] += chr(j)
elif i[1] == dataTypes.BYTE:
end = start+1
elif i[1] == dataTypes.UINT16 or i[1] == dataTypes.SINT16:
end = start+2
elif i[1] == dataTypes.UINT32 or i[1] == dataTypes.SINT32:
end = start+4
elif i[1] == dataTypes.UINT64 or i[1] == dataTypes.SINT64:
end = start+8
# Unpack if needed
if unpack:
data[i[0]] = unpackData(stream[start:end], i[1])
return data

View File

@ -1,36 +0,0 @@
from helpers import cryptHelper
import base64
import bcrypt
def checkOldPassword(password, salt, rightPassword):
"""
Check if password+salt corresponds to rightPassword
password -- input password
salt -- password's salt
rightPassword -- right password
return -- bool
"""
return (rightPassword == cryptHelper.crypt(password, "$2y$"+str(base64.b64decode(salt))))
def checkNewPassword(password, dbPassword):
"""
Check if a password (version 2) is right.
password -- input password
dbPassword -- the password in the database
return -- bool
"""
password = password.encode("utf8")
dbPassword = dbPassword.encode("utf8")
return bcrypt.hashpw(password, dbPassword) == dbPassword
def genBcrypt(password):
"""
Bcrypts a password.
password -- the password to hash.
return -- bytestring
"""
return bcrypt.hashpw(password.encode("utf8"), bcrypt.gensalt(10, b'2a'))

View File

@ -1,89 +0,0 @@
import tornado
import tornado.web
import tornado.gen
from tornado.ioloop import IOLoop
from objects import glob
from raven.contrib.tornado import SentryMixin
from raven.contrib.tornado import AsyncSentryClient
import gevent
class asyncRequestHandler(tornado.web.RequestHandler):
"""
Tornado asynchronous request handler
create a class that extends this one (requestHelper.asyncRequestHandler)
use asyncGet() and asyncPost() instad of get() and post().
Done. I'm not kidding.
"""
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, *args, **kwargs):
try:
yield tornado.gen.Task(runBackground, (self.asyncGet, tuple(args), dict(kwargs)))
except Exception as e:
yield tornado.gen.Task(self.captureException, exc_info=True)
finally:
if not self._finished:
self.finish()
@tornado.web.asynchronous
@tornado.gen.engine
def post(self, *args, **kwargs):
try:
yield tornado.gen.Task(runBackground, (self.asyncPost, tuple(args), dict(kwargs)))
except Exception as e:
yield tornado.gen.Task(self.captureException, exc_info=True)
finally:
if not self._finished:
self.finish()
def asyncGet(self, *args, **kwargs):
self.send_error(405)
self.finish()
def asyncPost(self, *args, **kwargs):
self.send_error(405)
self.finish()
def getRequestIP(self):
realIP = self.request.headers.get("X-Forwarded-For") if glob.cloudflare == True else self.request.headers.get("X-Real-IP")
if realIP != None:
return realIP
return self.request.remote_ip
def runBackground(data, callback):
"""
Run a function in the background.
Used to handle multiple requests at the same time
"""
func, args, kwargs = data
def _callback(result):
IOLoop.instance().add_callback(lambda: callback(result))
#glob.pool.apply_async(func, args, kwargs, _callback)
g = gevent.Greenlet(func, *args, **kwargs)
g.link(_callback)
g.start()
def checkArguments(arguments, requiredArguments):
"""
Check that every requiredArguments elements are in arguments
arguments -- full argument list, from tornado
requiredArguments -- required arguments list es: ["u", "ha"]
handler -- handler string name to print in exception. Optional
return -- True if all arguments are passed, none if not
"""
for i in requiredArguments:
if i not in arguments:
return False
return True
def printArguments(t):
"""
Print passed arguments, for debug purposes
t -- tornado object (self)
"""
print("ARGS::")
for i in t.request.arguments:
print ("{}={}".format(i, t.get_argument(i)))

View File

@ -1,41 +1,57 @@
from objects import glob import math
from constants import serverPackets
import psutil
import os import os
import signal
import sys import sys
import threading import threading
import signal import time
from helpers import logHelper as log
import psutil
from common.constants import bcolors
from common.log import logUtils as log
from constants import serverPackets
from helpers import consoleHelper
from objects import glob
def dispose():
"""
Perform some clean up. Called on shutdown.
:return:
"""
print("> Disposing server... ")
glob.fileBuffers.flushAll()
consoleHelper.printColored("Goodbye!", bcolors.GREEN)
def runningUnderUnix(): def runningUnderUnix():
""" """
Get if the server is running under UNIX or NT Get if the server is running under UNIX or NT
return --- True if running under UNIX, otherwise False :return: True if running under UNIX, otherwise False
""" """
return True if os.name == "posix" else False return True if os.name == "posix" else False
def scheduleShutdown(sendRestartTime, restart, message = "", delay=20):
def scheduleShutdown(sendRestartTime, restart, message = ""):
""" """
Schedule a server shutdown/restart Schedule a server shutdown/restart
sendRestartTime -- time (seconds) to wait before sending server restart packets to every client :param sendRestartTime: time (seconds) to wait before sending server restart packets to every client
restart -- if True, server will restart. if False, server will shudown :param restart: if True, server will restart. if False, server will shudown
message -- if set, send that message to every client to warn about the shutdown/restart :param message: if set, send that message to every client to warn about the shutdown/restart
:param delay: additional restart delay in seconds. Default: 20
:return:
""" """
# Console output # Console output
log.info("Pep.py will {} in {} seconds!".format("restart" if restart else "shutdown", sendRestartTime+20)) log.info("Pep.py will {} in {} seconds!".format("restart" if restart else "shutdown", sendRestartTime+delay), "bunker")
log.info("Sending server restart packets in {} seconds...".format(sendRestartTime)) log.info("Sending server restart packets in {} seconds...".format(sendRestartTime))
# Send notification if set # Send notification if set
if message != "": if message != "":
glob.tokens.enqueueAll(serverPackets.notification(message)) glob.streams.broadcast("main", serverPackets.notification(message))
# Schedule server restart packet # Schedule server restart packet
threading.Timer(sendRestartTime, glob.tokens.enqueueAll, [serverPackets.banchoRestart(50000)]).start() threading.Timer(sendRestartTime, glob.streams.broadcast, ["main", serverPackets.banchoRestart(delay*2*1000)]).start()
glob.restarting = True glob.restarting = True
# Restart/shutdown # Restart/shutdown
@ -44,44 +60,59 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
else: else:
action = shutdownServer action = shutdownServer
# Schedule actual server shutdown/restart 20 seconds after server restart packet, so everyone gets it # Schedule actual server shutdown/restart some seconds after server restart packet, so everyone gets it
threading.Timer(sendRestartTime+20, action).start() threading.Timer(sendRestartTime+delay, action).start()
def restartServer(): def restartServer():
"""Restart pep.py script""" """
Restart pep.py
:return:
"""
log.info("Restarting pep.py...") log.info("Restarting pep.py...")
dispose()
os.execv(sys.executable, [sys.executable] + sys.argv) os.execv(sys.executable, [sys.executable] + sys.argv)
def shutdownServer(): def shutdownServer():
"""Shutdown pep.py""" """
log.info("> Shutting down pep.py...") Shutdown pep.py
:return:
"""
log.info("Shutting down pep.py...")
dispose()
sig = signal.SIGKILL if runningUnderUnix() else signal.CTRL_C_EVENT sig = signal.SIGKILL if runningUnderUnix() else signal.CTRL_C_EVENT
os.kill(os.getpid(), sig) os.kill(os.getpid(), sig)
def getSystemInfo(): def getSystemInfo():
""" """
Get a dictionary with some system/server info Get a dictionary with some system/server info
return -- ["unix", "connectedUsers", "webServer", "cpuUsage", "totalMemory", "usedMemory", "loadAverage"] :return: ["unix", "connectedUsers", "webServer", "cpuUsage", "totalMemory", "usedMemory", "loadAverage"]
""" """
data = {"unix": runningUnderUnix(), "connectedUsers": len(glob.tokens.tokens), "matches": len(glob.matches.matches)}
data = {}
# Get if server is running under unix/nt
data["unix"] = runningUnderUnix()
# General stats # General stats
data["connectedUsers"] = len(glob.tokens.tokens) delta = time.time()-glob.startTime
data["matches"] = len(glob.matches.matches) days = math.floor(delta/86400)
delta -= days*86400
hours = math.floor(delta/3600)
delta -= hours*3600
minutes = math.floor(delta/60)
delta -= minutes*60
seconds = math.floor(delta)
data["uptime"] = "{}d {}h {}m {}s".format(days, hours, minutes, seconds)
data["cpuUsage"] = psutil.cpu_percent() data["cpuUsage"] = psutil.cpu_percent()
data["totalMemory"] = "{0:.2f}".format(psutil.virtual_memory()[0]/1074000000) memory = psutil.virtual_memory()
data["usedMemory"] = "{0:.2f}".format(psutil.virtual_memory()[3]/1074000000) data["totalMemory"] = "{0:.2f}".format(memory.total/1074000000)
data["usedMemory"] = "{0:.2f}".format(memory.active/1074000000)
# Unix only stats # Unix only stats
if data["unix"] == True: if data["unix"]:
data["loadAverage"] = os.getloadavg() data["loadAverage"] = os.getloadavg()
else: else:
data["loadAverage"] = (0,0,0) data["loadAverage"] = (0,0,0)

View File

@ -1,621 +0,0 @@
from helpers import passwordHelper
from constants import gameModes
from helpers import generalFunctions
from objects import glob
from helpers import logHelper as log
import time
from constants import privileges
def getID(username):
"""
Get username's user ID
db -- database connection
username -- user
return -- user id or False
"""
# Get user ID from db
userID = glob.db.fetch("SELECT id FROM users WHERE username = %s", [username])
# Make sure the query returned something
if userID == None:
return False
# Return user ID
return userID["id"]
def checkLogin(userID, password):
"""
Check userID's login with specified password
db -- database connection
userID -- user id
password -- plain md5 password
return -- True or False
"""
# Get password data
passwordData = glob.db.fetch("SELECT password_md5, salt, password_version FROM users WHERE id = %s", [userID])
# Make sure the query returned something
if passwordData == None:
return False
# Return valid/invalid based on the password version.
if passwordData["password_version"] == 2:
return passwordHelper.checkNewPassword(password, passwordData["password_md5"])
if passwordData["password_version"] == 1:
ok = passwordHelper.checkOldPassword(password, passwordData["salt"], passwordData["password_md5"])
if not ok: return False
newpass = passwordHelper.genBcrypt(password)
glob.db.execute("UPDATE users SET password_md5=%s, salt='', password_version='2' WHERE id = %s", [newpass, userID])
def exists(userID):
"""
Check if userID exists
userID -- user ID to check
return -- bool
"""
result = glob.db.fetch("SELECT id FROM users WHERE id = %s", [userID])
if result == None:
return False
else:
return True
def getSilenceEnd(userID):
"""
Get userID's **ABSOLUTE** silence end UNIX time
Remember to subtract time.time() to get the actual silence time
userID -- userID
return -- UNIX time
"""
return glob.db.fetch("SELECT silence_end FROM users WHERE id = %s", [userID])["silence_end"]
def silence(userID, seconds, silenceReason, author = 999):
"""
Silence someone
userID -- userID
seconds -- silence length in seconds
silenceReason -- Silence reason shown on website
author -- userID of who silenced the user. Default: 999
"""
# db qurey
silenceEndTime = int(time.time())+seconds
glob.db.execute("UPDATE users SET silence_end = %s, silence_reason = %s WHERE id = %s", [silenceEndTime, silenceReason, userID])
# Loh
targetUsername = getUsername(userID)
# TODO: exists check im drunk rn i need to sleep (stampa piede ubriaco confirmed)
if seconds > 0:
log.rap(author, "has silenced {} for {} seconds for the following reason: \"{}\"".format(targetUsername, seconds, silenceReason), True)
else:
log.rap(author, "has removed {}'s silence".format(targetUsername), True)
def getRankedScore(userID, gameMode):
"""
Get userID's ranked score relative to gameMode
userID -- userID
gameMode -- int value, see gameModes
return -- ranked score
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT ranked_score_"+modeForDB+" FROM users_stats WHERE id = %s", [userID])["ranked_score_"+modeForDB]
def getTotalScore(userID, gameMode):
"""
Get userID's total score relative to gameMode
userID -- userID
gameMode -- int value, see gameModes
return -- total score
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT total_score_"+modeForDB+" FROM users_stats WHERE id = %s", [userID])["total_score_"+modeForDB]
def getAccuracy(userID, gameMode):
"""
Get userID's average accuracy relative to gameMode
userID -- userID
gameMode -- int value, see gameModes
return -- accuracy
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT avg_accuracy_"+modeForDB+" FROM users_stats WHERE id = %s", [userID])["avg_accuracy_"+modeForDB]
def getGameRank(userID, gameMode):
"""
Get userID's **in-game rank** (eg: #1337) relative to gameMode
userID -- userID
gameMode -- int value, see gameModes
return -- game rank
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
result = glob.db.fetch("SELECT position FROM leaderboard_"+modeForDB+" WHERE user = %s", [userID])
if result == None:
return 0
else:
return result["position"]
def getPlaycount(userID, gameMode):
"""
Get userID's playcount relative to gameMode
userID -- userID
gameMode -- int value, see gameModes
return -- playcount
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT playcount_"+modeForDB+" FROM users_stats WHERE id = %s", [userID])["playcount_"+modeForDB]
def getUsername(userID):
"""
Get userID's username
userID -- userID
return -- username
"""
return glob.db.fetch("SELECT username FROM users WHERE id = %s", [userID])["username"]
def getFriendList(userID):
"""
Get userID's friendlist
userID -- userID
return -- list with friends userIDs. [0] if no friends.
"""
# Get friends from db
friends = glob.db.fetchAll("SELECT user2 FROM users_relationships WHERE user1 = %s", [userID])
if friends == None or len(friends) == 0:
# We have no friends, return 0 list
return [0]
else:
# Get only friends
friends = [i["user2"] for i in friends]
# Return friend IDs
return friends
def addFriend(userID, friendID):
"""
Add friendID to userID's friend list
userID -- user
friendID -- new friend
"""
# Make sure we aren't adding us to our friends
if userID == friendID:
return
# check user isn't already a friend of ours
if glob.db.fetch("SELECT id FROM users_relationships WHERE user1 = %s AND user2 = %s", [userID, friendID]) != None:
return
# Set new value
glob.db.execute("INSERT INTO users_relationships (user1, user2) VALUES (%s, %s)", [userID, friendID])
def removeFriend(userID, friendID):
"""
Remove friendID from userID's friend list
userID -- user
friendID -- old friend
"""
# Delete user relationship. We don't need to check if the relationship was there, because who gives a shit,
# if they were not friends and they don't want to be anymore, be it. ¯\_(ツ)_/¯
glob.db.execute("DELETE FROM users_relationships WHERE user1 = %s AND user2 = %s", [userID, friendID])
def getCountry(userID):
"""
Get userID's country **(two letters)**.
Use countryHelper.getCountryID with what that function returns
to get osu! country ID relative to that user
userID -- user
return -- country code (two letters)
"""
return glob.db.fetch("SELECT country FROM users_stats WHERE id = %s", [userID])["country"]
def getPP(userID, gameMode):
"""
Get userID's PP relative to gameMode
userID -- user
return -- PP
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT pp_{} FROM users_stats WHERE id = %s".format(modeForDB), [userID])["pp_{}".format(modeForDB)]
def setCountry(userID, country):
"""
Set userID's country (two letters)
userID -- userID
country -- country letters
"""
glob.db.execute("UPDATE users_stats SET country = %s WHERE id = %s", [country, userID])
def getShowCountry(userID):
"""
Get userID's show country status
userID -- userID
return -- True if country is shown, False if it's hidden
"""
country = glob.db.fetch("SELECT show_country FROM users_stats WHERE id = %s", [userID])
if country == None:
return False
return generalFunctions.stringToBool(country)
def logIP(userID, ip):
"""
User IP log
USED FOR MULTIACCOUNT DETECTION
"""
glob.db.execute("""INSERT INTO ip_user (userid, ip, occurencies) VALUES (%s, %s, 1)
ON DUPLICATE KEY UPDATE occurencies = occurencies + 1""", [userID, ip])
def saveBanchoSession(userID, ip):
"""
Save userid and ip of this token in bancho_sessions table.
Used to cache logins on LETS requests
"""
log.debug("Saving bancho session ({}::{}) in db".format(userID, ip))
glob.db.execute("INSERT INTO bancho_sessions (id, userid, ip) VALUES (NULL, %s, %s)", [userID, ip])
def deleteBanchoSessions(userID, ip):
"""Delete this bancho session from DB"""
log.debug("Deleting bancho session ({}::{}) from db".format(userID, ip))
try:
glob.db.execute("DELETE FROM bancho_sessions WHERE userid = %s AND ip = %s", [userID, ip])
except:
log.warning("Token for user: {} ip: {} doesn't exist".format(userID, ip))
def is2FAEnabled(userID):
"""Returns True if 2FA is enable for this account"""
result = glob.db.fetch("SELECT id FROM 2fa_telegram WHERE userid = %s LIMIT 1", [userID])
return True if result is not None else False
def check2FA(userID, ip):
"""Returns True if this IP is untrusted"""
if is2FAEnabled(userID) == False:
return False
result = glob.db.fetch("SELECT id FROM ip_user WHERE userid = %s AND ip = %s", [userID, ip])
return True if result is None else False
def getUserStats(userID, gameMode):
"""
Get all user stats relative to gameMode with only two queries
userID --
gameMode -- gameMode number
return -- dictionary with results
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
# Get stats
stats = glob.db.fetch("""SELECT
ranked_score_{gm} AS rankedScore,
avg_accuracy_{gm} AS accuracy,
playcount_{gm} AS playcount,
total_score_{gm} AS totalScore,
pp_{gm} AS pp
FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID])
# Get game rank
result = glob.db.fetch("SELECT position FROM leaderboard_{} WHERE user = %s LIMIT 1".format(modeForDB), [userID])
if result == None:
stats["gameRank"] = 0
else:
stats["gameRank"] = result["position"]
# Return stats + game rank
return stats
def isAllowed(userID):
"""
Check if userID is not banned or restricted
userID -- id of the user
return -- True if not banned or restricted, otherwise false.
"""
result = glob.db.fetch("SELECT privileges FROM users WHERE id = %s", [userID])
if result != None:
return (result["privileges"] & privileges.USER_NORMAL) and (result["privileges"] & privileges.USER_PUBLIC)
else:
return False
def isRestricted(userID):
"""
Check if userID is restricted
userID -- id of the user
return -- True if not restricted, otherwise false.
"""
result = glob.db.fetch("SELECT privileges FROM users WHERE id = %s", [userID])
if result != None:
return (result["privileges"] & privileges.USER_NORMAL) and not (result["privileges"] & privileges.USER_PUBLIC)
else:
return False
def isBanned(userID):
"""
Check if userID is banned
userID -- id of the user
return -- True if not banned, otherwise false.
"""
result = glob.db.fetch("SELECT privileges FROM users WHERE id = %s", [userID])
if result != None:
return not (result["privileges"] & 3 > 0)
else:
return True
def ban(userID):
"""
Ban userID
userID -- id of user
"""
banDateTime = int(time.time())
glob.db.execute("UPDATE users SET privileges = privileges & %s, ban_datetime = %s WHERE id = %s", [ ~(privileges.USER_NORMAL | privileges.USER_PUBLIC | privileges.USER_PENDING_VERIFICATION) , banDateTime, userID])
def unban(userID):
"""
Unban userID
userID -- id of user
"""
glob.db.execute("UPDATE users SET privileges = privileges | %s, ban_datetime = 0 WHERE id = %s", [ (privileges.USER_NORMAL | privileges.USER_PUBLIC) , userID])
def restrict(userID):
"""
Put userID in restricted mode
userID -- id of user
"""
banDateTime = int(time.time())
glob.db.execute("UPDATE users SET privileges = privileges & %s, ban_datetime = %s WHERE id = %s", [~privileges.USER_PUBLIC, banDateTime, userID])
def unrestrict(userID):
"""
Remove restricted mode from userID.
Same as unban().
userID -- id of user
"""
unban(userID)
def getPrivileges(userID):
"""
Return privileges for userID
userID -- id of user
return -- privileges number
"""
result = glob.db.fetch("SELECT privileges FROM users WHERE id = %s", [userID])
if result != None:
return result["privileges"]
else:
return 0
def setPrivileges(userID, priv):
"""
Set userID's privileges in db
userID -- id of user
priv -- privileges number
"""
glob.db.execute("UPDATE users SET privileges = %s WHERE id = %s", [priv, userID])
def isInPrivilegeGroup(userID, groupName):
groupPrivileges = glob.db.fetch("SELECT privileges FROM privileges_groups WHERE name = %s", [groupName])
if groupPrivileges == None:
return False
groupPrivileges = groupPrivileges["privileges"]
userToken = glob.tokens.getTokenFromUserID(userID)
if userToken != None:
userPrivileges = userToken.privileges
else:
userPrivileges = getPrivileges(userID)
return (userPrivileges == groupPrivileges) or (userPrivileges == (groupPrivileges | privileges.USER_DONOR))
def appendNotes(userID, notes, addNl = True):
"""
Append "notes" to current userID's "notes for CM"
userID -- id of user
notes -- text to append
addNl -- if True, prepend \n to notes. Optional. Default: True.
"""
if addNl == True:
notes = "\n"+notes
glob.db.execute("UPDATE users SET notes=CONCAT(COALESCE(notes, ''),%s) WHERE id = %s", [notes, userID])
def logHardware(userID, hashes, activation = False):
"""
Hardware log
USED FOR MULTIACCOUNT DETECTION
Peppy's botnet (client data) structure (new line = "|", already split)
[0] osu! version
[1] plain mac addressed, separated by "."
[2] mac addresses hash set
[3] unique ID
[4] disk ID
return -- True if hw is not banned, otherwise false
"""
# Make sure the strings are not empty
for i in hashes[2:5]:
if i == "":
log.warning("Invalid hash set ({}) for user {} in HWID check".format(hashes, userID), "bunk")
return False
# Run some HWID checks on that user if he is not restricted
if isRestricted(userID) == False:
# Get username
username = getUsername(userID)
# Get the list of banned or restricted users that have logged in from this or similar HWID hash set
banned = glob.db.fetchAll("""SELECT users.id as userid, hw_user.occurencies, users.username FROM hw_user
LEFT JOIN users ON users.id = hw_user.userid
WHERE hw_user.userid != %(userid)s
AND (IF(%(mac)s!='b4ec3c4334a0249dae95c284ec5983df', hw_user.mac = %(mac)s, 1) AND hw_user.unique_id = %(uid)s AND hw_user.disk_id = %(diskid)s)
AND (users.privileges & 3 != 3)""", {
"userid": userID,
"mac": hashes[2],
"uid": hashes[3],
"diskid": hashes[4],
})
for i in banned:
# Get the total numbers of logins
total = glob.db.fetch("SELECT COUNT(*) AS count FROM hw_user WHERE userid = %s LIMIT 1", [userID])
# and make sure it is valid
if total == None:
continue
total = total["count"]
# Calculate 10% of total
perc = (total*10)/100
if i["occurencies"] >= perc:
# If the banned user has logged in more than 10% of the times from this user, restrict this user
restrict(userID)
appendNotes(userID, "-- Logged in from HWID ({hwid}) used more than 10% from user {banned} ({bannedUserID}), who is banned/restricted.".format(
hwid=hashes[2:5],
banned=i["username"],
bannedUserID=i["userid"]
))
log.warning("**{user}** ({userID}) has been restricted because he has logged in from HWID _({hwid})_ used more than 10% from banned/restricted user **{banned}** ({bannedUserID}), **possible multiaccount**.".format(
user=username,
userID=userID,
hwid=hashes[2:5],
banned=i["username"],
bannedUserID=i["userid"]
), "cm")
# Update hash set occurencies
glob.db.execute("""
INSERT INTO hw_user (id, userid, mac, unique_id, disk_id, occurencies) VALUES (NULL, %s, %s, %s, %s, 1)
ON DUPLICATE KEY UPDATE occurencies = occurencies + 1
""", [userID, hashes[2], hashes[3], hashes[4]])
# Optionally, set this hash as 'used for activation'
if activation == True:
glob.db.execute("UPDATE hw_user SET activated = 1 WHERE userid = %s AND mac = %s AND unique_id = %s AND disk_id = %s", [userID, hashes[2], hashes[3], hashes[4]])
# Access granted, abbiamo impiegato 3 giorni
# We grant access even in case of login from banned HWID
# because we call restrict() above so there's no need to deny the access.
return True
def resetPendingFlag(userID, success=True):
"""
Remove pending flag from an user.
userID -- ID of the user
success -- if True, set USER_PUBLIC and USER_NORMAL flags too
"""
glob.db.execute("UPDATE users SET privileges = privileges & %s WHERE id = %s LIMIT 1", [~privileges.USER_PENDING_VERIFICATION, userID])
if success == True:
glob.db.execute("UPDATE users SET privileges = privileges | %s WHERE id = %s LIMIT 1", [(privileges.USER_PUBLIC | privileges.USER_NORMAL), userID])
def verifyUser(userID, hashes):
# Check for valid hash set
for i in hashes[2:5]:
if i == "":
log.warning("Invalid hash set ({}) for user {} while verifying the account".format(str(hashes), userID), "bunk")
return False
# Get username
username = getUsername(userID)
# Make sure there are no other accounts activated with this exact mac/unique id/hwid
match = glob.db.fetchAll("SELECT userid FROM hw_user WHERE (IF(%(mac)s != 'b4ec3c4334a0249dae95c284ec5983df', mac = %(mac)s, 1) AND unique_id = %(uid)s AND disk_id = %(diskid)s) AND userid != %(userid)s AND activated = 1 LIMIT 1", {
"mac": hashes[2],
"uid": hashes[3],
"diskid": hashes[4],
"userid": userID
})
if match:
# This is a multiaccount, restrict other account and ban this account
# Get original userID and username (lowest ID)
originalUserID = match[0]["userid"]
originalUsername = getUsername(originalUserID)
# Ban this user and append notes
ban(userID) # this removes the USER_PENDING_VERIFICATION flag too
appendNotes(userID, "-- {}'s multiaccount ({}), found HWID match while verifying account ({})".format(originalUsername, originalUserID, hashes[2:5]))
appendNotes(originalUserID, "-- Has created multiaccount {} ({})".format(username, userID))
# Restrict the original
restrict(originalUserID)
# Discord message
log.warning("User **{originalUsername}** ({originalUserID}) has been restricted because he has created multiaccount **{username}** ({userID}). The multiaccount has been banned.".format(
originalUsername=originalUsername,
originalUserID=originalUserID,
username=username,
userID=userID
), "cm")
# Disallow login
return False
else:
# No matches found, set USER_PUBLIC and USER_NORMAL flags and reset USER_PENDING_VERIFICATION flag
resetPendingFlag(userID)
log.info("User **{}** ({}) has verified his account with hash set _{}_".format(username, userID, hashes[2:5]), "cm")
# Allow login
return True
def hasVerifiedHardware(userID):
"""
userID -- id of the user
return -- True if hwid activation data is in db, otherwise false
"""
data = glob.db.fetch("SELECT id FROM hw_user WHERE userid = %s AND activated = 1 LIMIT 1", [userID])
if data != None:
return True
return False

View File

@ -6,32 +6,32 @@ by Joel Rosdahl, licensed under the GNU GPL 2 License.
Most of the reference code from miniircd was used for the low-level logic. Most of the reference code from miniircd was used for the low-level logic.
The high-level code has been rewritten to make it compatible with pep.py. The high-level code has been rewritten to make it compatible with pep.py.
""" """
import sys
import traceback
import socket
import select
import time
import re
import hashlib import hashlib
from helpers import logHelper as log import re
import select
import socket
import sys
import time
import traceback
from objects import glob
from helpers import chatHelper as chat
import raven import raven
class Client: from common.log import logUtils as log
""" from common.ripple import userUtils
IRC Client object from helpers import chatHelper as chat
""" from objects import glob
__linesep_regexp = re.compile(r"\r?\n")
class Client:
__linesep_regexp = re.compile(r"\r?\n")
def __init__(self, server, sock): def __init__(self, server, sock):
""" """
Initialize a Client object Initialize a Client object
server -- server object :param server: server object
sock -- socket connection object :param sock: socket connection object
:return:
""" """
self.__timestamp = time.time() self.__timestamp = time.time()
self.__readbuffer = "" self.__readbuffer = ""
@ -42,8 +42,10 @@ class Client:
self.server = server self.server = server
self.socket = sock self.socket = sock
(self.ip, self.port) = sock.getpeername() (self.ip, self.port) = sock.getpeername()
self.username = "" self.IRCUsername = ""
self.banchoUsername = ""
self.supposedUsername = "" self.supposedUsername = ""
self.supposedUserID = 0
self.joinedChannels = [] self.joinedChannels = []
def messageChannel(self, channel, command, message, includeSelf=False): def messageChannel(self, channel, command, message, includeSelf=False):
@ -57,7 +59,8 @@ class Client:
Add a message (basic string) to client buffer. Add a message (basic string) to client buffer.
This is the lowest possible level. This is the lowest possible level.
msg -- message to add :param msg: message to add
:return:
""" """
self.__writebuffer += msg + "\r\n" self.__writebuffer += msg + "\r\n"
@ -66,7 +69,7 @@ class Client:
""" """
Return this client's write buffer size Return this client's write buffer size
return -- write buffer size :return: write buffer size
""" """
return len(self.__writebuffer) return len(self.__writebuffer)
@ -75,7 +78,8 @@ class Client:
""" """
Add an IRC-like message to client buffer. Add an IRC-like message to client buffer.
msg -- message (without IRC stuff) :param msg: message (without IRC stuff)
:return:
""" """
self.message(":{} {}".format(self.server.host, msg)) self.message(":{} {}".format(self.server.host, msg))
@ -84,13 +88,14 @@ class Client:
""" """
Add an IRC-like message to client buffer with code Add an IRC-like message to client buffer with code
code -- response code :param code: response code
message -- response message :param message: response message
nickname -- receiver nickname :param nickname: receiver nickname
channel -- optional :param channel: optional
:return:
""" """
if nickname == "": if nickname == "":
nickname = self.username nickname = self.IRCUsername
if channel != "": if channel != "":
channel = " "+channel channel = " "+channel
self.reply("{code:03d} {nickname}{channel} :{message}".format(code=code, nickname=nickname, channel=channel, message=message)) self.reply("{code:03d} {nickname}{channel} :{message}".format(code=code, nickname=nickname, channel=channel, message=message))
@ -100,7 +105,8 @@ class Client:
""" """
Add a 403 reply (no such channel) to client buffer. Add a 403 reply (no such channel) to client buffer.
channel -- meh :param channel:
:return:
""" """
self.replyCode(403, "{} :No such channel".format(channel)) self.replyCode(403, "{} :No such channel".format(channel))
@ -109,7 +115,8 @@ class Client:
""" """
Add a 461 reply (not enough parameters) to client buffer Add a 461 reply (not enough parameters) to client buffer
command -- command that had not enough parameters :param command: name of the command that had not enough parameters
:return:
""" """
self.replyCode(403, "{} :Not enough parameters".format(command)) self.replyCode(403, "{} :Not enough parameters".format(command))
@ -118,8 +125,9 @@ class Client:
""" """
Disconnects this client from the IRC server Disconnects this client from the IRC server
quitmsg -- IRC quit message. Default: 'Client quit' :param quitmsg: IRC quit message. Default: 'Client quit'
callLogout -- if True, call logoutEvent on bancho :param callLogout: if True, call logoutEvent on bancho
:return:
""" """
# Send error to client and close socket # Send error to client and close socket
self.message("ERROR :{}".format(quitmsg)) self.message("ERROR :{}".format(quitmsg))
@ -130,12 +138,16 @@ class Client:
self.server.removeClient(self, quitmsg) self.server.removeClient(self, quitmsg)
# Bancho logout # Bancho logout
if callLogout == True: if callLogout and self.banchoUsername != "":
chat.IRCDisconnect(self.username) chat.IRCDisconnect(self.IRCUsername)
def readSocket(self): def readSocket(self):
"""Read data coming from this client socket""" """
Read data coming from this client socket
:return:
"""
try: try:
# Try to read incoming data from socket # Try to read incoming data from socket
data = self.socket.recv(2 ** 10) data = self.socket.recv(2 ** 10)
@ -143,7 +155,7 @@ class Client:
quitmsg = "EOT" quitmsg = "EOT"
except socket.error as x: except socket.error as x:
# Error while reading data, this client will be disconnected # Error while reading data, this client will be disconnected
data = "" data = bytes()
quitmsg = x quitmsg = x
if data: if data:
@ -158,7 +170,11 @@ class Client:
def parseBuffer(self): def parseBuffer(self):
"""Parse self.__readbuffer, get command, arguments and call its handler""" """
Parse self.__readbuffer, get command, arguments and call its handler
:return:
"""
# Get lines from buffer # Get lines from buffer
lines = self.__linesep_regexp.split(self.__readbuffer) lines = self.__linesep_regexp.split(self.__readbuffer)
self.__readbuffer = lines[-1] self.__readbuffer = lines[-1]
@ -195,17 +211,25 @@ class Client:
def writeSocket(self): def writeSocket(self):
"""Write buffer to socket""" """
Write buffer to socket
:return:
"""
try: try:
sent = self.socket.send(self.__writebuffer.encode()) sent = self.socket.send(self.__writebuffer.encode())
log.debug("[IRC] [{}:{}] <- {}".format(self.ip, self.port, self.__writebuffer[:sent])) log.debug("[IRC] [{}:{}] <- {}".format(self.ip, self.port, self.__writebuffer[:sent]))
self.__writebuffer = self.__writebuffer[sent:] self.__writebuffer = self.__writebuffer[sent:]
except socket.error as x: except socket.error as x:
self.disconnect(x) self.disconnect(str(x))
def checkAlive(self): def checkAlive(self):
"""Check if this client is still connected""" """
Check if this client is still connected.
If the client is dead, disconnect it.
:return:
"""
now = time.time() now = time.time()
if self.__timestamp + 180 < now: if self.__timestamp + 180 < now:
self.disconnect("ping timeout") self.disconnect("ping timeout")
@ -221,11 +245,19 @@ class Client:
def sendLusers(self): def sendLusers(self):
"""Send lusers response to this client""" """
Send lusers response to this client
:return:
"""
self.replyCode(251, "There are {} users and 0 services on 1 server".format(len(glob.tokens.tokens))) self.replyCode(251, "There are {} users and 0 services on 1 server".format(len(glob.tokens.tokens)))
def sendMotd(self): def sendMotd(self):
"""Send MOTD to this client""" """
Send MOTD to this client
:return:
"""
self.replyCode(375, "- {} Message of the day - ".format(self.server.host)) self.replyCode(375, "- {} Message of the day - ".format(self.server.host))
if len(self.server.motd) == 0: if len(self.server.motd) == 0:
self.replyCode(422, "MOTD File is missing") self.replyCode(422, "MOTD File is missing")
@ -250,9 +282,10 @@ class Client:
m = hashlib.md5() m = hashlib.md5()
m.update(arguments[0].encode("utf-8")) m.update(arguments[0].encode("utf-8"))
tokenHash = m.hexdigest() tokenHash = m.hexdigest()
supposedUsername = glob.db.fetch("SELECT users.username FROM users LEFT JOIN irc_tokens ON users.id = irc_tokens.userid WHERE irc_tokens.token = %s LIMIT 1", [tokenHash]) supposedUser = glob.db.fetch("SELECT users.username, users.id FROM users LEFT JOIN irc_tokens ON users.id = irc_tokens.userid WHERE irc_tokens.token = %s LIMIT 1", [tokenHash])
if supposedUsername: if supposedUser:
self.supposedUsername = supposedUsername["username"] self.supposedUsername = chat.fixUsernameForIRC(supposedUser["username"])
self.supposedUserID = supposedUser["id"]
self.__handleCommand = self.registerHandler self.__handleCommand = self.registerHandler
else: else:
# Wrong IRC Token # Wrong IRC Token
@ -270,29 +303,36 @@ class Client:
nick = arguments[0] nick = arguments[0]
# Make sure this is the first time we set our nickname # Make sure this is the first time we set our nickname
if self.username != "": if self.IRCUsername != "":
self.reply("432 * %s :Erroneous nickname" % nick) self.reply("432 * %s :Erroneous nickname" % nick)
return return
# Make sure the IRC token was correct: # Make sure the IRC token was correct:
# (self.supposedUsername is already fixed for IRC)
if nick.lower() != self.supposedUsername.lower(): if nick.lower() != self.supposedUsername.lower():
self.reply("464 :Password incorrect") self.reply("464 :Password incorrect")
return return
# Make sure that the user is not banned/restricted:
if not userUtils.isAllowed(self.supposedUserID):
self.reply("465 :You're banned")
return
# Make sure we are not connected to Bancho # Make sure we are not connected to Bancho
token = glob.tokens.getTokenFromUsername(nick) token = glob.tokens.getTokenFromUsername(chat.fixUsernameForBancho(nick), True)
if token != None: if token is not None:
self.reply("433 * {} :Nickname is already in use".format(nick)) self.reply("433 * {} :Nickname is already in use".format(nick))
return return
# Make sure we are not already connected from IRC with that name
for _, value in self.server.clients.items():
if value.username == self.username and value != self:
self.reply("433 * {} :Nickname is already in use".format(nick))
return
# Everything seems fine, set username (nickname) # Everything seems fine, set username (nickname)
self.username = nick self.IRCUsername = nick # username for IRC
self.banchoUsername = chat.fixUsernameForBancho(self.IRCUsername) # username for bancho
# Disconnect other IRC clients from the same user
for _, value in self.server.clients.items():
if value.IRCUsername.lower() == self.IRCUsername.lower() and value != self:
value.disconnect(quitmsg="Connected from another client")
return
elif command == "USER": elif command == "USER":
# Ignore USER command, we use nickname only # Ignore USER command, we use nickname only
return return
@ -305,9 +345,9 @@ class Client:
return return
# If we now have a valid username, connect to bancho and send IRC welcome stuff # If we now have a valid username, connect to bancho and send IRC welcome stuff
if self.username != "": if self.IRCUsername != "":
# Bancho connection # Bancho connection
chat.IRCConnect(self.username) chat.IRCConnect(self.banchoUsername)
# IRC reply # IRC reply
self.replyCode(1, "Welcome to the Internet Relay Network") self.replyCode(1, "Welcome to the Internet Relay Network")
@ -318,30 +358,30 @@ class Client:
self.sendMotd() self.sendMotd()
self.__handleCommand = self.mainHandler self.__handleCommand = self.mainHandler
def quitHandler(self, command, arguments): def quitHandler(self, _, arguments):
"""QUIT command handler""" """QUIT command handler"""
self.disconnect(self.username if len(arguments) < 1 else arguments[0]) self.disconnect(self.IRCUsername if len(arguments) < 1 else arguments[0])
def joinHandler(self, command, arguments): def joinHandler(self, _, arguments):
"""JOIN command handler""" """JOIN command handler"""
if len(arguments) < 1: if len(arguments) < 1:
self.reply461("JOIN") self.reply461("JOIN")
return return
# Get bancho token object # Get bancho token object
token = glob.tokens.getTokenFromUsername(self.username) token = glob.tokens.getTokenFromUsername(self.banchoUsername)
if token == None: if token is None:
return return
# TODO: Part all channels # TODO: Part all channels
if arguments[0] == "0": if arguments[0] == "0":
return
'''for (channelname, channel) in self.channels.items(): '''for (channelname, channel) in self.channels.items():
self.message_channel(channel, "PART", channelname, True) self.message_channel(channel, "PART", channelname, True)
self.channel_log(channel, "left", meta=True) self.channel_log(channel, "left", meta=True)
server.remove_member_from_channel(self, channelname) server.remove_member_from_channel(self, channelname)
self.channels = {} self.channels = {}
return''' return'''
return
# Get channels to join list # Get channels to join list
channels = arguments[0].split(",") channels = arguments[0].split(",")
@ -354,13 +394,13 @@ class Client:
continue continue
# Attempt to join the channel # Attempt to join the channel
response = chat.IRCJoinChannel(self.username, channel) response = chat.IRCJoinChannel(self.banchoUsername, channel)
if response == 0: if response == 0:
# Joined successfully # Joined successfully
self.joinedChannels.append(channel) self.joinedChannels.append(channel)
# Let everyone in this channel know that we've joined # Let everyone in this channel know that we've joined
self.messageChannel(channel, "{} JOIN".format(self.username), channel, True) self.messageChannel(channel, "{} JOIN".format(self.IRCUsername), channel, True)
# Send channel description (topic) # Send channel description (topic)
description = glob.channels.channels[channel].description description = glob.channels.channels[channel].description
@ -370,16 +410,18 @@ class Client:
self.replyCode(332, description, channel=channel) self.replyCode(332, description, channel=channel)
# Build connected users list # Build connected users list
users = glob.channels.channels[channel].getConnectedUsers()[:] if "chat/{}".format(channel) not in glob.streams.streams:
self.reply403(channel)
continue
users = glob.streams.streams["chat/{}".format(channel)].clients
usernames = [] usernames = []
for user in users: for user in users:
token = glob.tokens.getTokenFromUserID(user) if user not in glob.tokens.tokens:
if token == None:
continue continue
usernames.append(token.username) usernames.append(chat.fixUsernameForIRC(glob.tokens.tokens[user].username))
usernames = " ".join(usernames) usernames = " ".join(usernames)
# Send IRC users lis # Send IRC users list
self.replyCode(353, usernames, channel="= {}".format(channel)) self.replyCode(353, usernames, channel="= {}".format(channel))
self.replyCode(366, "End of NAMES list", channel=channel) self.replyCode(366, "End of NAMES list", channel=channel)
elif response == 403: elif response == 403:
@ -387,15 +429,15 @@ class Client:
self.reply403(channel) self.reply403(channel)
continue continue
def partHandler(self, command, arguments): def partHandler(self, _, arguments):
"""PART command handler""" """PART command handler"""
if len(arguments) < 1: if len(arguments) < 1:
self.reply461("PART") self.reply461("PART")
return return
# Get bancho token object # Get bancho token object
token = glob.tokens.getTokenFromUsername(self.username) token = glob.tokens.getTokenFromUsername(self.banchoUsername)
if token == None: if token is None:
return return
# Get channels to part list # Get channels to part list
@ -409,7 +451,7 @@ class Client:
continue continue
# Attempt to part the channel # Attempt to part the channel
response = chat.IRCPartChannel(self.username, channel) response = chat.IRCPartChannel(self.banchoUsername, channel)
if response == 0: if response == 0:
# No errors, remove channel from joinedChannels # No errors, remove channel from joinedChannels
self.joinedChannels.remove(channel) self.joinedChannels.remove(channel)
@ -429,36 +471,39 @@ class Client:
if len(arguments) == 1: if len(arguments) == 1:
self.replyCode(412, "No text to send") self.replyCode(412, "No text to send")
return return
recipient = arguments[0] recipientIRC = arguments[0]
message = arguments[1] message = arguments[1]
# Send the message to bancho and reply # Send the message to bancho and reply
response = chat.sendMessage(self.username, recipient, message, toIRC=False) if not recipientIRC.startswith("#"):
recipientBancho = chat.fixUsernameForBancho(recipientIRC)
else:
recipientBancho = recipientIRC
response = chat.sendMessage(self.banchoUsername, recipientBancho, message, toIRC=False)
if response == 404: if response == 404:
self.replyCode(404, "Cannot send to channel", channel=recipient) self.replyCode(404, "Cannot send to channel", channel=recipientIRC)
return return
elif response == 403: elif response == 403:
self.replyCode(403, "No such channel", channel=recipient) self.replyCode(403, "No such channel", channel=recipientIRC)
return return
elif response == 401: elif response == 401:
self.replyCode(401, "No such nick/channel", channel=recipient) self.replyCode(401, "No such nick/channel", channel=recipientIRC)
return return
# Send the message to IRC and bancho # Send the message to IRC and bancho
if recipient.startswith("#"): if recipientIRC.startswith("#"):
# Public message (IRC) # Public message (IRC)
if recipient not in glob.channels.channels: if recipientIRC not in glob.channels.channels:
self.replyCode(401, "No such nick/channel", channel=recipient) self.replyCode(401, "No such nick/channel", channel=recipientIRC)
return return
for _, value in self.server.clients.items(): for _, value in self.server.clients.items():
if recipient in value.joinedChannels and value != self: if recipientIRC in value.joinedChannels and value != self:
value.message(":{} PRIVMSG {} :{}".format(self.username, recipient, message)) value.message(":{} PRIVMSG {} :{}".format(self.IRCUsername, recipientIRC, message))
#self.messageChannel(recipient, command, "{} :{}".format(recipient, message))
else: else:
# Private message (IRC) # Private message (IRC)
for _, value in self.server.clients.items(): for _, value in self.server.clients.items():
if value.username == recipient: if value.IRCUsername == recipientIRC:
value.message(":{} PRIVMSG {} :{}".format(self.username, recipient, message)) value.message(":{} PRIVMSG {} :{}".format(self.IRCUsername, recipientIRC, message))
def motdHandler(self, command, arguments): def motdHandler(self, command, arguments):
"""MOTD command handler""" """MOTD command handler"""
@ -468,7 +513,7 @@ class Client:
"""LUSERS command handler""" """LUSERS command handler"""
self.sendLusers() self.sendLusers()
def pingHandler(self, command, arguments): def pingHandler(self, _, arguments):
"""PING command handler""" """PING command handler"""
if len(arguments) < 1: if len(arguments) < 1:
self.replyCode(409, "No origin specified") self.replyCode(409, "No origin specified")
@ -479,10 +524,17 @@ class Client:
"""(fake) PONG command handler""" """(fake) PONG command handler"""
pass pass
def awayHandler(self, _, arguments):
"""AWAY command handler"""
response = chat.IRCAway(self.banchoUsername, " ".join(arguments))
self.replyCode(response, "You are no longer marked as being away" if response == 305 else "You have been marked as being away")
def mainHandler(self, command, arguments): def mainHandler(self, command, arguments):
"""Handler for post-login commands""" """
Handler for post-login commands
"""
handlers = { handlers = {
#"AWAY": away_handler, "AWAY": self.awayHandler,
#"ISON": ison_handler, #"ISON": ison_handler,
"JOIN": self.joinHandler, "JOIN": self.joinHandler,
#"LIST": list_handler, #"LIST": list_handler,
@ -508,36 +560,35 @@ class Client:
self.replyCode(421, "Unknown command ({})".format(command)) self.replyCode(421, "Unknown command ({})".format(command))
class Server: class Server:
def __init__(self, port): def __init__(self, port):
self.host = socket.getfqdn("127.0.0.1")[:63] self.host = glob.conf.config["irc"]["hostname"]
self.port = port self.port = port
self.clients = {} # Socket --> Client instance. self.clients = {} # Socket - - > Client instance.
self.motd = ["Welcome to pep.py's embedded IRC server!", "This is a VERY simple IRC server and it's still in beta.", "Expect things to crash and not work as expected :("] self.motd = ["Welcome to pep.py's embedded IRC server!", "This is a VERY simple IRC server and it's still in beta.", "Expect things to crash and not work as expected :("]
def forceDisconnection(self, username): def forceDisconnection(self, username, isBanchoUsername=True):
""" """
Disconnect someone from IRC if connected Disconnect someone from IRC if connected
username -- victim :param username: victim
:param isBanchoUsername: if True, username is a bancho username, else convert it to a bancho username
:return:
""" """
for _, value in self.clients.items(): for _, value in self.clients.items():
if value.username == username: if (value.IRCUsername == username and not isBanchoUsername) or (value.banchoUsername == username and isBanchoUsername):
value.disconnect(callLogout=False) value.disconnect(callLogout=False)
break# or dictionary changes size during iteration break # or dictionary changes size during iteration
def banchoJoinChannel(self, username, channel): def banchoJoinChannel(self, username, channel):
""" """
Let every IRC client connected to a specific client know that 'username' joined the channel from bancho Let every IRC client connected to a specific client know that 'username' joined the channel from bancho
username -- username of bancho user :param username: username of bancho user
channel -- joined channel name :param channel: joined channel name
:return:
""" """
username = chat.fixUsernameForIRC(username)
for _, value in self.clients.items(): for _, value in self.clients.items():
if channel in value.joinedChannels: if channel in value.joinedChannels:
value.message(":{} JOIN {}".format(username, channel)) value.message(":{} JOIN {}".format(username, channel))
@ -546,9 +597,11 @@ class Server:
""" """
Let every IRC client connected to a specific client know that 'username' parted the channel from bancho Let every IRC client connected to a specific client know that 'username' parted the channel from bancho
username -- username of bancho user :param username: username of bancho user
channel -- joined channel name :param channel: joined channel name
:return:
""" """
username = chat.fixUsernameForIRC(username)
for _, value in self.clients.items(): for _, value in self.clients.items():
if channel in value.joinedChannels: if channel in value.joinedChannels:
value.message(":{} PART {}".format(username, channel)) value.message(":{} PART {}".format(username, channel))
@ -557,37 +610,45 @@ class Server:
""" """
Send a message to IRC when someone sends it from bancho Send a message to IRC when someone sends it from bancho
fro -- sender username :param fro: sender username
to -- receiver username :param to: receiver username
message -- text of the message :param message: text of the message
:return:
""" """
fro = chat.fixUsernameForIRC(fro)
to = chat.fixUsernameForIRC(to)
if to.startswith("#"): if to.startswith("#"):
# Public message # Public message
for _, value in self.clients.items(): for _, value in self.clients.items():
if to in value.joinedChannels and value.username != fro: if to in value.joinedChannels and value.IRCUsername != fro:
value.message(":{} PRIVMSG {} :{}".format(fro, to, message)) value.message(":{} PRIVMSG {} :{}".format(fro, to, message))
else: else:
# Private message # Private message
for _, value in self.clients.items(): for _, value in self.clients.items():
if value.username == to and value.username != fro: if value.IRCUsername == to and value.IRCUsername != fro:
value.message(":{} PRIVMSG {} :{}".format(fro, to, message)) value.message(":{} PRIVMSG {} :{}".format(fro, to, message))
def removeClient(self, client, quitmsg): def removeClient(self, client, _):
""" """
Remove a client from connected clients Remove a client from connected clients
client -- client object :param client: client object
quitmsg -- QUIT argument, useless atm :return:
""" """
if client.socket in self.clients: if client.socket in self.clients:
del self.clients[client.socket] del self.clients[client.socket]
def start(self): def start(self):
"""Start IRC server main loop""" """
Start IRC server main loop
:return:
"""
# Sentry # Sentry
if glob.sentry == True: sentryClient = None
sentryClient = raven.Client(glob.conf.config["sentry"]["ircdns"]) if glob.sentry:
sentryClient = raven.Client(glob.conf.config["sentry"]["ircdsn"])
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ -607,7 +668,7 @@ class Server:
[x.socket for x in self.clients.values() [x.socket for x in self.clients.values()
if x.writeBufferSize() > 0], if x.writeBufferSize() > 0],
[], [],
2) 1)
# Handle incoming connections # Handle incoming connections
for x in iwtd: for x in iwtd:
@ -618,7 +679,7 @@ class Server:
try: try:
self.clients[conn] = Client(self, conn) self.clients[conn] = Client(self, conn)
log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1])) log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1]))
except socket.error as e: except socket.error:
try: try:
conn.close() conn.close()
except: except:
@ -637,9 +698,15 @@ class Server:
lastAliveCheck = now lastAliveCheck = now
except: except:
log.error("[IRC] Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc())) log.error("[IRC] Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
if glob.sentry == True: if glob.sentry and sentryClient is not None:
sentryClient.captureException() sentryClient.captureException()
def main(port=6667): def main(port=6667):
"""
Create and start an IRC server
:param port: IRC port. Default: 6667
:return:
"""
glob.ircServer = Server(port) glob.ircServer = Server(port)
glob.ircServer.start() glob.ircServer.start()

View File

@ -1,5 +1,9 @@
# TODO: Rewrite this shit
from common import generalUtils
from constants import serverPackets
from objects import glob from objects import glob
from helpers import generalFunctions from common.log import logUtils as log
class banchoConfig: class banchoConfig:
""" """
@ -8,35 +12,56 @@ class banchoConfig:
config = {"banchoMaintenance": False, "freeDirect": True, "menuIcon": "", "loginNotification": ""} config = {"banchoMaintenance": False, "freeDirect": True, "menuIcon": "", "loginNotification": ""}
def __init__(self, __loadFromDB = True): def __init__(self, loadFromDB = True):
""" """
Initialize a banchoConfig object (and load bancho_settings from db) Initialize a banchoConfig object (and load bancho_settings from db)
[__loadFromDB -- if True, load values from db. If False, don't load values. Default: True] loadFromDB -- if True, load values from db. If False, don't load values. Optional.
""" """
if loadFromDB:
if __loadFromDB:
try: try:
self.loadSettings() self.loadSettings()
except: except:
raise raise
def loadSettings(self): def loadSettings(self):
""" """
(re)load bancho_settings from DB and set values in config array (re)load bancho_settings from DB and set values in config array
""" """
self.config["banchoMaintenance"] = generalUtils.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'bancho_maintenance'")["value_int"])
self.config["banchoMaintenance"] = generalFunctions.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'bancho_maintenance'")["value_int"]) self.config["freeDirect"] = generalUtils.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'free_direct'")["value_int"])
self.config["freeDirect"] = generalFunctions.stringToBool(glob.db.fetch("SELECT value_int FROM bancho_settings WHERE name = 'free_direct'")["value_int"]) mainMenuIcon = glob.db.fetch("SELECT file_id, url FROM main_menu_icons WHERE is_current = 1 LIMIT 1")
self.config["menuIcon"] = glob.db.fetch("SELECT value_string FROM bancho_settings WHERE name = 'menu_icon'")["value_string"] if mainMenuIcon is None:
self.config["menuIcon"] = ""
else:
imageURL = "https://i.ppy.sh/{}.png".format(mainMenuIcon["file_id"])
self.config["menuIcon"] = "{}|{}".format(imageURL, mainMenuIcon["url"])
self.config["loginNotification"] = glob.db.fetch("SELECT value_string FROM bancho_settings WHERE name = 'login_notification'")["value_string"] self.config["loginNotification"] = glob.db.fetch("SELECT value_string FROM bancho_settings WHERE name = 'login_notification'")["value_string"]
def setMaintenance(self, __maintenance):
def setMaintenance(self, maintenance):
""" """
Turn on/off bancho maintenance mode. Write new value to db too Turn on/off bancho maintenance mode. Write new value to db too
__maintenance -- if True, turn on maintenance mode. If false, turn it off maintenance -- if True, turn on maintenance mode. If false, turn it off
""" """
self.config["banchoMaintenance"] = maintenance
glob.db.execute("UPDATE bancho_settings SET value_int = %s WHERE name = 'bancho_maintenance'", [int(maintenance)])
self.config["banchoMaintenance"] = __maintenance def reload(self):
glob.db.execute("UPDATE bancho_settings SET value_int = %s WHERE name = 'bancho_maintenance'", [int(__maintenance)]) # Reload settings from bancho_settings
glob.banchoConf.loadSettings()
# Reload channels too
glob.channels.loadChannels()
# And chat filters
glob.chatFilters.loadFilters()
# Send new channels and new bottom icon to everyone
glob.streams.broadcast("main", serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
glob.streams.broadcast("main", serverPackets.channelInfoEnd())
for key, value in glob.channels.channels.items():
if value.publicRead and not value.hidden:
glob.streams.broadcast("main", serverPackets.channelInfo(key))

View File

@ -1,79 +1,44 @@
import logging
from constants import exceptions
from objects import glob from objects import glob
class channel: class channel:
""" def __init__(self, name, description, publicRead, publicWrite, temp, hidden):
A chat channel
"""
def __init__(self, __name, __description, __publicRead, __publicWrite, temp, hidden):
""" """
Create a new chat channel object Create a new chat channel object
__name -- channel name :param name: channel name
__description -- channel description :param description: channel description
__publicRead -- bool, if true channel can be read by everyone, if false it can be read only by mods/admins :param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
__publicWrite -- bool, same as public read but relative to write permissions :param publicWrite: same as public read, but regards writing permissions
temp -- if True, channel will be deleted when there's no one in the channel :param temp: if True, this channel will be deleted when there's no one in this channel
hidden -- if True, channel won't be shown in channels list :param hidden: if True, thic channel won't be shown in channels list
""" """
self.name = name
self.name = __name self.description = description
self.description = __description self.publicRead = publicRead
self.publicRead = __publicRead self.publicWrite = publicWrite
self.publicWrite = __publicWrite
self.moderated = False self.moderated = False
self.temp = temp self.temp = temp
self.connectedUsers = [999] # Fokabot is always connected to every channels (otherwise it doesn't show up in IRC users list)
self.hidden = hidden self.hidden = hidden
# Client name (#spectator/#multiplayer) # Make Foka join the channel
self.clientName = self.name fokaToken = glob.tokens.getTokenFromUserID(999)
if fokaToken is not None:
try:
fokaToken.joinChannel(self)
except exceptions.userAlreadyInChannelException:
logging.warning("FokaBot has already joined channel {}".format(self.name))
@property
def isSpecial(self):
return any(self.name.startswith(x) for x in ("#spect_", "#multi_"))
@property
def clientName(self):
if self.name.startswith("#spect_"): if self.name.startswith("#spect_"):
self.clientName = "#spectator" return "#spectator"
elif self.name.startswith("#multi_"): elif self.name.startswith("#multi_"):
self.clientName = "#multiplayer" return "#multiplayer"
return self.name
def userJoin(self, __userID):
"""
Add a user to connected users
__userID -- user ID that joined the channel
"""
if __userID not in self.connectedUsers:
self.connectedUsers.append(__userID)
def userPart(self, __userID):
"""
Remove a user from connected users
__userID -- user ID that left the channel
"""
if __userID in self.connectedUsers:
self.connectedUsers.remove(__userID)
# Remove temp channels if empty or there's only fokabot connected
l = len(self.connectedUsers)
if self.temp == True and ((l == 0) or (l == 1 and 999 in self.connectedUsers)):
glob.channels.removeChannel(self.name)
def getConnectedUsers(self):
"""
Get connected user IDs list
return -- connectedUsers list
"""
return self.connectedUsers
def getConnectedUsersCount(self):
"""
Count connected users
return -- connected users number
"""
return len(self.connectedUsers)

View File

@ -1,22 +1,18 @@
from objects import glob from common.log import logUtils as log
from objects import channel from objects import channel
from helpers import logHelper as log from objects import glob
from helpers import chatHelper as chat
class channelList: class channelList:
""" def __init__(self):
Channel list self.channels = {}
channels -- dictionary. key: channel name, value: channel object
"""
channels = {}
def loadChannels(self): def loadChannels(self):
""" """
Load chat channels from db and add them to channels dictionary Load chat channels from db and add them to channels list
:return:
""" """
# Get channels from DB # Get channels from DB
channels = glob.db.fetchAll("SELECT * FROM bancho_channels") channels = glob.db.fetchAll("SELECT * FROM bancho_channels")
@ -27,43 +23,67 @@ class channelList:
publicWrite = True if i["public_write"] == 1 else False publicWrite = True if i["public_write"] == 1 else False
self.addChannel(i["name"], i["description"], publicRead, publicWrite) self.addChannel(i["name"], i["description"], publicRead, publicWrite)
def addChannel(self, name, description, publicRead, publicWrite, temp = False, hidden = False): def addChannel(self, name, description, publicRead, publicWrite, temp = False, hidden = False):
""" """
Add a channel object to channels dictionary Add a channel to channels list
name -- channel name :param name: channel name
description -- channel description :param description: channel description
publicRead -- bool, if true channel can be read by everyone, if false it can be read only by mods/admins :param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
publicWrite -- bool, same as public read but relative to write permissions :param publicWrite: same as public read, but regards writing permissions
temp -- if True, channel will be deleted when there's no one in the channel. Optional. Default = False. :param temp: if True, this channel will be deleted when there's no one in this channel
hidden -- if True, channel will be hidden in channels list. Optional. Default = False. :param hidden: if True, thic channel won't be shown in channels list
:return:
""" """
glob.streams.add("chat/{}".format(name))
self.channels[name] = channel.channel(name, description, publicRead, publicWrite, temp, hidden) self.channels[name] = channel.channel(name, description, publicRead, publicWrite, temp, hidden)
log.info("Created channel {}".format(name)) log.info("Created channel {}".format(name))
def addTempChannel(self, name): def addTempChannel(self, name):
""" """
Add a temporary channel (like #spectator or #multiplayer), gets deleted when there's no one in the channel Add a temporary channel (like #spectator or #multiplayer), gets deleted when there's no one in the channel
and it's hidden in channels list and it's hidden in channels list
name -- channel name :param name: channel name
return -- True if channel was created, False if failed :return: True if the channel was created, otherwise False
""" """
if name in self.channels: if name in self.channels:
return False return False
glob.streams.add("chat/{}".format(name))
self.channels[name] = channel.channel(name, "Chat", True, True, True, True) self.channels[name] = channel.channel(name, "Chat", True, True, True, True)
log.info("Created temp channel {}".format(name)) log.info("Created temp channel {}".format(name))
def addHiddenChannel(self, name):
"""
Add a hidden channel. It's like a normal channel and must be deleted manually,
but it's not shown in channels list.
:param name: channel name
:return: True if the channel was created, otherwise False
"""
if name in self.channels:
return False
glob.streams.add("chat/{}".format(name))
self.channels[name] = channel.channel(name, "Chat", True, True, False, True)
log.info("Created hidden channel {}".format(name))
def removeChannel(self, name): def removeChannel(self, name):
""" """
Removes a channel from channels list Removes a channel from channels list
name -- channel name :param name: channel name
:return:
""" """
if name not in self.channels: if name not in self.channels:
log.debug("{} is not in channels list".format(name)) log.debug("{} is not in channels list".format(name))
return return
#glob.streams.broadcast("chat/{}".format(name), serverPackets.channelKicked(name))
stream = glob.streams.getStream("chat/{}".format(name))
if stream is not None:
for token in stream.clients:
if token in glob.tokens.tokens:
chat.partChannel(channel=name, token=glob.tokens.tokens[token], kick=True)
glob.streams.dispose("chat/{}".format(name))
glob.streams.remove("chat/{}".format(name))
self.channels.pop(name) self.channels.pop(name)
log.info("Removed channel {}".format(name)) log.info("Removed channel {}".format(name))

View File

@ -1,9 +1,20 @@
class chatFilters: class chatFilters:
def __init__(self, fileName="filters.txt"): def __init__(self, fileName="filters.txt"):
"""
Initialize chat filters
:param fileName: name of the file containing filters. Default: filters.txt
"""
self.filters = {} self.filters = {}
self.loadFilters(fileName) self.loadFilters(fileName)
def loadFilters(self, fileName="filters.txt"): def loadFilters(self, fileName="filters.txt"):
"""
Load filters from a file
:param fileName: name of the file containing filters. Default: filters.txt
:return:
"""
# Reset chat filters # Reset chat filters
self.filters = {} self.filters = {}
@ -16,17 +27,28 @@ class chatFilters:
for line in data: for line in data:
# Get old/new word and save it in dictionary # Get old/new word and save it in dictionary
lineSplit = line.split("=") lineSplit = line.split("=")
self.filters[lineSplit[0]] = lineSplit[1].replace("\n", "") self.filters[lineSplit[0].lower()] = lineSplit[1].replace("\n", "")
def filterMessage(self, message): def filterMessage(self, message):
"""
Replace forbidden words with filtered ones
:param message: normal message
:return: filtered message
"""
return message
"""
# Split words by spaces # Split words by spaces
messageTemp = message.split(" ") messageTemp = message.split(" ")
# Check each word # Check each word
for word in messageTemp: for word in messageTemp:
lowerWord = word.lower()
# If the word is filtered, replace it # If the word is filtered, replace it
if word in self.filters: if lowerWord in self.filters:
message = message.replace(word, self.filters[word]) message = message.replace(word, self.filters[lowerWord])
# Return filtered message # Return filtered message
return message return message
"""

View File

@ -1,20 +0,0 @@
import threading
class fileLocks:
def __init__(self):
# Dictionary containing threading.Lock s
self.locks = {}
def lockFile(self, fileName):
if fileName in self.locks:
# Acquire existing lock
self.locks[fileName].acquire()
else:
# Create new lock and acquire it
self.locks[fileName] = threading.Lock()
self.locks[fileName].acquire()
def unlockFile(self, fileName):
if fileName in self.locks:
# Release lock if it exists
self.locks[fileName].release()

View File

@ -1,55 +1,54 @@
"""FokaBot related functions""" """FokaBot related functions"""
from helpers import userHelper
from objects import glob
from constants import actions
from constants import serverPackets
from constants import fokabotCommands
import re import re
from helpers import generalFunctions
from common import generalUtils
from common.constants import actions
from common.ripple import userUtils
from constants import fokabotCommands
from constants import serverPackets
from objects import glob
# Tillerino np regex, compiled only once to increase performance # Tillerino np regex, compiled only once to increase performance
npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)") npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)")
def connect(): def connect():
"""Add FokaBot to connected users and send userpanel/stats packet to everyone""" """
Connect FokaBot to Bancho
:return:
"""
glob.BOT_NAME = userUtils.getUsername(999)
token = glob.tokens.addToken(999) token = glob.tokens.addToken(999)
token.actionID = actions.idle token.actionID = actions.IDLE
glob.tokens.enqueueAll(serverPackets.userPanel(999)) glob.streams.broadcast("main", serverPackets.userPanel(999))
####glob.tokens.enqueueAll(serverPackets.userStats(999)) glob.streams.broadcast("main", serverPackets.userStats(999))
# NOTE: Debug thing to set all users as connected
#users = glob.db.fetchAll("SELECT id FROM users")
#for i in users:
# t = glob.tokens.addToken(i["id"])
# t.actionID = actions.idle
def disconnect(): def disconnect():
"""Remove FokaBot from connected users""" """
Disconnect FokaBot from Bancho
:return:
"""
glob.tokens.deleteToken(glob.tokens.getTokenFromUserID(999)) glob.tokens.deleteToken(glob.tokens.getTokenFromUserID(999))
def fokabotResponse(fro, chan, message): def fokabotResponse(fro, chan, message):
""" """
Check if a message has triggered fokabot (and return its response) Check if a message has triggered FokaBot
fro -- sender username (for permissions stuff with admin commands) :param fro: sender username
chan -- channel name :param chan: channel name (or receiver username)
message -- message :param message: chat mesage
:return: FokaBot's response or False if no response
return -- fokabot's response string or False
""" """
for i in fokabotCommands.commands: for i in fokabotCommands.commands:
# Loop though all commands # Loop though all commands
#if i["trigger"] in message: if re.compile("^{}( (.+)?)?$".format(i["trigger"])).match(message.strip()):
if generalFunctions.strContains(message, i["trigger"]):
# message has triggered a command # message has triggered a command
# Make sure the user has right permissions # Make sure the user has right permissions
if i["privileges"] != None: if i["privileges"] is not None:
# Rank = x # Rank = x
if userHelper.getPrivileges(userHelper.getID(fro)) & i["privileges"] == 0: if userUtils.getPrivileges(userUtils.getID(fro)) & i["privileges"] == 0:
return False return False
# Check argument number # Check argument number
@ -58,10 +57,10 @@ def fokabotResponse(fro, chan, message):
return "Wrong syntax: {} {}".format(i["trigger"], i["syntax"]) return "Wrong syntax: {} {}".format(i["trigger"], i["syntax"])
# Return response or execute callback # Return response or execute callback
if i["callback"] == None: if i["callback"] is None:
return i["response"] return i["response"]
else: else:
return i["callback"](fro, chan, message[1:]) return i["callback"](fro, chan, message[1:])
# No commands triggered # No commands triggered
return False return False

View File

@ -1,34 +1,59 @@
"""Global objects and variables""" """Global objects and variables"""
from objects import tokenList import time
from common.ddog import datadogClient
from common.files import fileBuffer, fileLocks
from objects import channelList from objects import channelList
from objects import matchList from objects import matchList
from objects import fileLocks from objects import streamList
from objects import tokenList
from common.web import schiavo
try: try:
with open("version") as f: with open("version") as f:
VERSION = f.read() VERSION = f.read().strip()
if VERSION == "": if VERSION == "":
raise raise Exception
except: except:
VERSION = "¯\_(xd)_/¯" VERSION = "Unknown"
DATADOG_PREFIX = "peppy"
BOT_NAME = "FokaBot"
application = None
db = None db = None
redis = None
conf = None conf = None
banchoConf = None banchoConf = None
tokens = tokenList.tokenList() tokens = tokenList.tokenList()
channels = channelList.channelList() channels = channelList.channelList()
matches = matchList.matchList() matches = matchList.matchList()
restarting = False
fLocks = fileLocks.fileLocks() fLocks = fileLocks.fileLocks()
fileBuffers = fileBuffer.buffersList()
schiavo = schiavo.schiavo()
dog = datadogClient.datadogClient()
verifiedCache = {} verifiedCache = {}
cloudflare = False
chatFilters = None chatFilters = None
pool = None
ircServer = None
busyThreads = 0
debug = False debug = False
outputRequestTime = False outputRequestTime = False
outputPackets = False outputPackets = False
discord = False
gzip = False gzip = False
localize = False localize = False
sentry = False sentry = False
irc = False
restarting = False
startTime = int(time.time())
streams = streamList.streamList()
# Additional modifications
COMMON_VERSION_REQ = "1.2.1"
try:
with open("common/version") as f:
COMMON_VERSION = f.read().strip()
except:
COMMON_VERSION = "Unknown"

View File

@ -1,24 +0,0 @@
'''
import threading
class task:
def __init__(self, function, args = (), kwargs = {}):
self.function = function
self.args = args
self.kwargs = kwargs
class logThread:
def __init__(self):
self.thread = threading.Thread()
self.queue = []
def enqueue(self, function, args = (), kwargs = {}):
self.queue.append(task(function, args, kwargs))
def run(self):
for i in self.queue:
self.thread = threading.Thread(i.function, i.args, i.kwargs)
self.thread.run()
self.thread.join()
self.queue = []
'''

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More