Commit Graph

505 Commits

Author SHA1 Message Date
Guangcong Luo
d6f5404e7e Rename CommandParser to Chat
We had a lot of discussion in Dev and a somewhat-close poll, but in
the end "Chat" was a better name than "Messages", and also has the
advantage of being shorter (which is nice for Chat.html and
Chat.plural which should be short).
2016-09-30 18:31:15 -07:00
panpawn
f5271bb753 Refactor confirmed status to trusted (#2798)
It should be noted that various user functions have been renamed as well to reflect this change as well.
2016-09-29 13:02:14 -07:00
Quinton Lee
dce63c36d7 Validator: support supplementary banlists (#2794) 2016-09-29 00:41:06 -07:00
Guangcong Luo
b459771619 Refactor CommandParser
CommandParser.parse has been refactored so most of its logic now
resides in CommandContext#parse.

CommandParser recursion is now a lot lighter. Instead of make a new
copy of the CommandContext, the existing one is reused.

messages.js no longer needs to exist; its functionality is now in
CommandContext#parse and CommandContext#canTalk. Its duplicate code
is gone now! :D

The inNamespace option of CommandContext#parse appears unused and has
been removed.

Users#matchesRank has been renamed Users#authAtLeast.
2016-09-28 22:13:07 -07:00
Guangcong Luo
e87c072fe8 Suppress crash in roomgame 2016-09-27 04:23:40 -04:00
Guangcong Luo
53dd09fba0 Refactor modjoin
This unifies modjoin checks (both Room#modjoin and Room#staffRoom join
restrictions) under one function, Room#checkModjoin.

This makes it easier for commands to check whether a user should know
about a room's existence, which, previously, had been duplicated
unreliably in each command's implementation.

Fixes #2426
2016-09-24 23:14:16 -07:00
Guangcong Luo
6d3a3bf7f0 Suppress crash in Users
Closes #2775
2016-09-24 13:50:59 -07:00
Bär Halberkamp
baad5271a4 Add /blacklistname 2016-09-24 22:49:51 +02:00
Ivo Julca
5bacd55a91
Drop messages sent to non-existent rooms 2016-09-19 20:09:08 -05:00
Ivo Julca
8713026c8b
Fix several crashes due to missing room properties 2016-09-18 01:05:26 -05:00
Ivo Julca
ce9cdecafd Drop commands sent to rooms from outside 2016-09-17 19:42:15 -05:00
Guangcong Luo
816dd3380d Suppress crashes with roomgame handling
In theory, this code shouldn't crash, but I don't really have the
time to track down exactly what the problem is right now.
2016-09-17 04:31:11 -04:00
Guangcong Luo
05ae323fcd Refactor roombans/blacklists
Roombans/blacklists have been mostly rewritten from scratch.

The new code mostly uses the same patterns as global punishments.

In addition:
- /ban has been renamed /globalban
- globalbans and blacklists now require a reason
- bans and blacklists in public rooms now show up in global modlog
- blacklist syntax is different: /blacklist and /unblacklist
- ban/blacklist display in /whoare is now more detailed
2016-09-16 10:27:26 -07:00
Guangcong Luo
7a7b46bc1e High priority blacklists fixes
This isn't all the work that needs to be done on blacklists, but it's
the highest-priority changes.

- blacklists.tsv has been renamed room-punishments.tsv
- The format everywhere has changed to roomid:userid, rather than
  roomid|userid
- roompunishments.tsv's format is now `Room ID:User ID, IPs and alts`
  rather than `User ID, Room ID|IPs and alts`, which is more sane and
  also cuts down on repetition of room IDs

Those are the changes that affect storage format, which are highest
priority because I don't want to support the previous format.

Other changes include:
- Punishments.roombannedIps renamed to Punishments.roomIps
- Punishments.roombannedUserids renamed to Punishments.roomUserids
- Some refactoring for ES6 destructuring
- Various bugfixes
2016-09-15 06:10:54 -07:00
Bär Halberkamp
28c0a2a22c Rewrite roombans to be timed as well (#2545)
Also implement blacklists
2016-09-15 04:35:00 -07:00
Guangcong Luo
310fdaa898 Refactor out Room#chat
Room#chat has now been folded into CommandParser.parse.

User#chat now directly calls CommandParser.parse, saving a line of
stack, and eliminating a function that never did much, really.
2016-09-12 19:01:35 -07:00
Guangcong Luo
c030c84245 Move "too many battles" messages to monitor.js 2016-09-10 15:52:16 -04:00
Guangcong Luo
6f53fcff3a Remove User#broadcasting
This flag seems like it's no longer used for anything, and leads to
weird bugs.
2016-09-04 00:02:22 -05:00
Guangcong Luo
98071aca1a Make the 'root' permission global
The 'root' permission used to be applied globally, but a refactor made
it apply per-room, so admins wouldn't have the permission while in
private rooms and rooms they have other roomauth in.

This once again makes 'root' a global permission.
2016-09-04 00:02:22 -05:00
Guangcong Luo
54b672fe4e Start refactoring for template strings
This commit introduces Tools.html and Tools.plural, helper functions
for string construction.

Tools.html is a template tag function that escapes HTML inside the
template string.

Tools.plural is a helper function that takes a passed Number, Array,
Set, or Map and returns a string representing whether or not it's
plural.

It also starts doing some refactors of some files to make it clear how
I expect code style for template strings to look.

Previously, we used ' for IDs, " for English text, and ' for code.

We should now be using ' for IDs, ` for English text, and ` for code.
2016-08-28 04:35:43 -05:00
Guangcong Luo
4523078519 Refactor User#games from Map to Set
User#games no longer retains games; it instead gets them from
Rooms(roomid).game.

The Trivia tests needed to be fixed for fidelity to continue passing.
2016-08-27 02:16:58 -05:00
Guangcong Luo
7017029dc1 Track connection.protocol
This should make it easier to hunt down that bug that's causing SockJS
not to disconnect.

(I have suspicions that it's related to websocket-raw but it's always
nice to get more data...)
2016-08-27 01:01:09 -05:00
Guangcong Luo
7a623b150b Fix bug in user count
be75115e4 accidentally messed up how user merging works.
2016-08-22 16:18:54 -05:00
Guangcong Luo
bcc417baf9 Refactor User#games to Map
User#games, previously a null-prototype roomid:game Object,
is now User#games, a roomid:game Map.

It would have been refactored into a roomid Set, but I'm afraid of
inconsistent state, even more so than I am of the corresponding
problem in Connection#inRooms. TODO: that.

This also fixes the handling of the race condition where a ladder
battle starts after a user starts a name change but before the name
change finishes.

Now, the battle is force-forfeited. Perhaps the ladder battle
should be prevented if the user changes name...
2016-08-22 03:58:15 -05:00
Guangcong Luo
1a1530f4ff Refactor Connection#rooms to Set
Connection#rooms, previously a null-prototype roomid:room Object,
is now Connection#inRooms, a roomid Set.

This, incidentally, makes it stop retaining rooms, which may make the
GC's job easier and may also lead to unexpected bugs if we get
inconsistent state (we often do get inconsistent state, so look
forward to that!)

The rename is mostly to put it in line with the new User#inRooms,
and for ease of greppability without running into Rooms.rooms.
2016-08-22 03:57:52 -05:00
Guangcong Luo
be75115e49 Refactor Users#roomCount to Set
Users#roomCount, previously a null-prototype roomid:count Object,
is now Users#inRooms, a roomid Set.

The new name is "inRooms" rather than "rooms" mostly for ease of
greppability. I'm kind of tired of getting Rooms.rooms when
grepping for ".rooms"

This is the next step in the process of using Maps/Sets instead of
null-proto Objects for maps/sets we add/remove to/from a lot.

I tried to get rid of the room counter completely, but that made
iterating a user's rooms take tens of milliseconds rather than
tens of microseconds, which is unacceptably slow for how often we do
that.

Not actively tracking the number of connections in a room does not
change the asymptotic complexity of any function. It slows down
leaveRoom but doesn't change its asymptotic complexity (nor does
it slow it down in any noticeable way).

leaveRoom was, incidentally, kinda gnarly code which is now a lot
cleaner. Yay!
2016-08-22 03:57:08 -05:00
Guangcong Luo
74548071cf Fix bug in namefilter
The namefilter error message wasn't being properly displayed.
2016-08-20 23:37:09 -04:00
panpawn
ead14d413b When Users#setGroup is called, use Config ranks (#2707)
This makes it so that when Users#setGroup is called, it looks slightly less hard-coded to be a whatever symbol a regular user is (should that symbol ever change)
2016-08-20 22:30:36 -05:00
Guangcong Luo
85e739f353 Refactor ResourceMonitor
This is a major refactor.

countConnection, countBattle, countPrepBattle, and countGroupChat have
been rewritten to use a new TimedCounter class that extends Map. Newer
versions of V8 seem to deal poorly with hash-mode Objects, so I hope
this approach is better.

countBattle now reports to Monitor.adminlog (console log and Upper
Staff room if it exists) instead of Monitor.log. This makes it match
countConnection, since non-programmers can't really do anything about
it anyway.

The teamValidatorChanged/Unchanged counters have been removed. They
were added to measure the proportion of times a validator has resulted
in no changes (the answer is approximately 50%).

countNetworkUse is now only active in emergency mode. It does nothing
but take up RAM normally.

countCmd has been removed entirely. The original code was buggy (only
blocking 1 out of every 15 client queries even when spammed) and
was only active in emergency mode. It should probably be rewritten
from scratch the next time we have a need for it.
2016-08-20 04:24:55 -05:00
panpawn
bbaed4a934 Simplify high load game number checks (#2678)
Sparked from d105beeacd discussion.
2016-08-20 03:48:20 -05:00
Bär Halberkamp
127214230f Update usergroup before merging connections
This makes it so confirmed users that get their lock removed through changing to that account don't retain the lock symbol even though they're not locked
2016-08-19 23:29:18 +02:00
panpawn
0afc96b81d Slightly refactor User#deconfirm (#2701) 2016-08-19 04:21:14 -05:00
Ivo Julca
875a81c749 Support autoconfirmed/confirmed as PM Modchat settings
- Also adds User#matchesRank(rank: string), which can be reused in every place
where we are concerned about global authority.
2016-08-17 00:09:59 -05:00
Guangcong Luo
525a1393a7 Fix Users#prevNames tracking 2016-08-13 02:06:06 -05:00
Guangcong Luo
938d2f16d2 Fix matchmakingOK crash 2016-08-09 12:19:16 -05:00
Guangcong Luo
60c0cd576e Refactor User#resetName and User#forceRename
The two functions shared a lot of duplicate code which is no longer necessary.
2016-08-09 12:18:58 -05:00
Guangcong Luo
29ad92128b Refactor Users.users/Users.prevUsers updates
Updating these maps are now done in the specific functions Users.add,
Users.delete, Users.move, and Users.merge.

No other function should modify these maps at all.
2016-08-09 01:25:24 -05:00
Guangcong Luo
9781fac19c Fix namefilter support 2016-08-08 23:56:29 -05:00
Guangcong Luo
34650dd455 Refactor Rooms.rooms and Rooms.aliases to Map 2016-08-08 16:46:11 -05:00
Ben Davies
4fd88c8c19 Users: don't add userids to user.prevNames on rename if it never changed (#2675) 2016-08-06 18:21:28 -05:00
Quinton Lee
1daec1a8f4 Hide nicknames of Pokemon used by locked users (#2639) 2016-07-24 02:28:12 -06:00
Guangcong Luo
c1d8f185b4 Slightly refactor pruneInactive
Mostly inconsequential, but this new code better reflects the code
style I'd like to have in PS.
2016-07-06 09:21:11 -05:00
Guangcong Luo
5354e18629 Refactor chatQueue to use roomid
The chatQueue previously put a reference to the room directly in the
chatQueue array. This refactors it to use a room ID.

This mostly doesn't matter much, but it's nice not to have references
to rooms outside of the room, and makes for slightly cleaner code by
not needing the weird workaround to see if the room has expired.
2016-07-06 09:21:11 -05:00
Ivo Julca
976610df75 Forfeit games on inactive user pruning
Fixes #1826
2016-07-01 10:22:31 -05:00
Ivo Julca
ce6a5d308a Tournaments now disallow name changes 2016-07-01 09:49:13 -05:00
Guangcong Luo
748c621007 Refactor in room.getAuth
Removes some code duplication.
2016-06-26 17:11:09 -07:00
Guangcong Luo
e1d3210415 Very minor readability refactor in Users 2016-06-23 19:50:58 -04:00
Guangcong Luo
0171fb1488 Deprecate namelock symbol
Namelock used to get its own symbol, but it's been rolled in with
the regular lock symbol. It's easy enough for people who need to to
tell namelocked and regularly locked users apart, anyway, and this
should be less confusing to users who aren't familiar with the
distinction.
2016-06-23 19:50:58 -04:00
Guangcong Luo
db85587fb0 Full support for lock/ban reasons
Lock/ban reasons are now fully supported by the Punishments system.
2016-06-17 04:39:55 -04:00
Guangcong Luo
55857f0b1b Fix namefilter long name handling 2016-06-11 20:14:52 -04:00