Commit Graph

247 Commits

Author SHA1 Message Date
Ivo Julca
14d0716e7e Refactor Simulator to use the PM API
This removes Simulator.battles in favor of each process' tracking their own battles.
2016-03-23 02:44:46 -05:00
Guangcong Luo
c74aee6bb8 Simplify battle.rated and battle.tour
`battle.tour` is now just a reference to the tour.

`battle.rated` is now just the minimum Elo rating of the two players
in the battle.

With the new RoomGame battles, neither of their old values are
necessary anymore.
2016-02-19 05:18:40 -06:00
Guangcong Luo
b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00
Guangcong Luo
c7bb5b5315 Add RoomGame support for /joingame, /leavegame
The old commands /joinbattle, /leavebattle are now /joingame and
/leavegame, and can be implemented by any RoomGame.
2016-01-19 01:47:26 -08:00
Guangcong Luo
2e679efd89 Fix battle count tracking 2016-01-16 04:03:51 -05:00
Guangcong Luo
a13575e5d7 Add RoomGame support for /forfeit, /choose 2016-01-14 15:44:06 -08:00
Guangcong Luo
86a3283cb6 Remove players at end of battles
Users are no longer considered players after a battle has ended. This
makes for better interaction with the roomgame list.
2016-01-08 00:46:05 -06:00
Guangcong Luo
08813ed2c1 Better roomgame titles for battles 2016-01-08 00:44:54 -06:00
Guangcong Luo
de5cf4e5d1 Send roomgame list in updateSearch
updateSearch now sends active roomgames in addition to formats being
searched.
2016-01-08 00:44:00 -06:00
Guangcong Luo
9d245a1652 Revert "Revert "Remove explicit decimal radix from parseInt""
This reverts commit 55df20be60.
2016-01-07 18:45:50 -06:00
Guangcong Luo
3bfdb16bcb Fix battle room subchannels
Battle rooms now once again send precise HP information for pokemon
on your team.
2016-01-07 13:24:40 -06:00
Slayer95
55df20be60 Revert "Remove explicit decimal radix from parseInt" 2016-01-05 12:56:32 -05:00
Bär Halberkamp
c254c663d3 Remove explicit decimal radix from parseInt 2016-01-05 17:35:12 +01:00
Guangcong Luo
c0d707c1e1 Ensure players get up-to-date HP information 2015-12-09 06:24:58 -05:00
Guangcong Luo
13a90c3096 Fix avatar display when rejoining battles 2015-12-05 23:28:31 -05:00
Guangcong Luo
580c464e83 Work around client error when renaming
Apparently the client can't handle requests being re-sent. To-do:
figure out why.
2015-12-05 23:27:49 -05:00
Guangcong Luo
81beefb462 Fix crash caused by refactor
Battle no longer inherits from RoomGame
2015-12-04 15:05:51 -05:00
Guangcong Luo
ce756e6212 Add new RoomGame event onUpdateConnection
onUpdateConnection is called when a user in a room merges with
another user. There are various corner cases when one might want
to handle this situation differently from onConnect

Also document the events in room-game.js in more detail, and fix
up simulator.js's RoomGame implementation a bit.
2015-12-04 05:59:29 -05:00
Guangcong Luo
341ab3b684 Refactor simulator.js to new RoomGame API
This is a huge refactor that's a half-scratch rewrite of simulator.js.

Everything seems to be working so far, but with such a huge change,
I wouldn't be surprised if something went wrong.
2015-12-03 18:30:47 -06:00
Guangcong Luo
e6125e34de Refactor user.battles to user.games
This is a small part of a larger refactor to make a more general
games system.
2015-12-03 18:30:47 -06:00
Ivo Julca
90973d5c0c Style fixes
- Cut down excessive spacing
- Add braces to missing conditionals
2015-11-07 17:08:09 -05:00
Ivo Julca
0479d2b729 Clean up handling of variable bindings in switch statements 2015-11-06 21:58:36 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Guangcong Luo
ab71ae20fe Refactor ResourceMonitor into monitor.js
ResourceMonitor has been moved from app.js into monitor.js and
renamed to simply Monitor. It also gains the ability to fine-
grained control the log level, although in a pretty crude way.

Monitor.debug - bugs in PS's engine that we need to fix
someday - by default, these aren't reported

Monitor.warn - issues that suggest an attacker or poorly
coded custom client - these should probably be looked at

Monitor.notice - issues that staff probably want to know.
These are usually also written to the Staff room.
2015-10-04 17:02:17 -04:00
Ivo Julca
a0d2a59875 Fix replays being uploaded under an alt after player rename 2015-07-07 03:18:08 -05:00
Guangcong Luo
e0efc92d12 Slightly more console output 2015-05-12 02:33:07 -04:00
Ivo Julca
4222ffb5df Dependant support: make sure that relative paths are resolved properly 2015-05-11 15:38:18 -05:00
Morfent
ce1724e179 Replace all s.substr(x, 1) with s.charAt(x) 2015-04-06 21:20:43 -03:00
Ivo Julca
e276f56d60 Battle#resendRequest's argument is now a connection, rather than user
- The higher specificity saves bandwidth and suppresses a client crash when another user connection joins the battle.
2014-12-25 18:18:21 -05:00
Ivo Julca
688bd5f9e4 Add missing sideupdate message type to simulator 2014-12-10 14:00:53 -05:00
小太
5027be79fb Add jscs as a style checker, and add some extra jshint options 2014-09-29 18:38:01 +10:00
Guangcong Luo
265eced415 Stop users from joining battles they're already in 2014-09-16 22:14:04 -04:00
Guangcong Luo
9bd804838f Implement subchannels
This pushes most of the work of dealing with `|split` from the
main (room) process to the socket process.
2014-08-25 23:48:33 -04:00
Ivo Julca
b3b435c1fd Battle.active now defaults to false.
This fixes the issue of players being unable to join any battles they start.
2014-08-25 00:01:00 -05:00
Guangcong Luo
af2026436a More style fixes and Gulpfile updates
JSHint is now a fair bit stricter, and is now correctly checking
files in `mods/`.

The code has been fixed to match the new stricter standards.

JSHint has now caught its second actual bug: Gen 5 Pinap Berry
was Ice instead of Grass.
2014-08-10 20:43:53 -04:00
Guangcong Luo
12b673bb49 Fix style errors; update gulpfile
I used a hack to make the multiple declaration errors go away,
so all that remained in jsHint were actual errors, which I've
now mostly fixed.

All this linting ended up uncovering one actual bug: Uproar's
message not showing. It's a very minor bug in a move no one uses,
so I'm going to fold it into this commit.
2014-08-10 18:06:44 -04:00
小太
5c8fc7b982 Space after function for anonymous functions 2014-04-22 01:58:16 +10:00
小太
6fb3bc332a Spaces around operators and === instead of == 2014-04-22 01:56:11 +10:00
Slayer95
05e7060474 Deprecate 'toUserid' global
Replaced by 'toId'.
2014-04-18 16:49:16 -05:00
Slayer95
75559362b4 Rename global config to Config 2014-04-17 01:12:28 -04:00
Guangcong Luo
692f47fc0a Support dynamically spawning simulator processes 2014-04-17 00:16:15 -04:00
小太
4f6a3e9c36 Merge remote-tracking branch 'upstream/master' into tournaments-frontend
Conflicts:
	package.json
2014-03-10 12:15:35 +11:00
Tyler Stark
bff353cc58 Second Pass at cleaning up the code. These are pretty safe edits that include adding 0 to decimal values, fixing variables that are declared multiple times, and removing duplicate keys 2014-02-09 23:38:57 -06:00
Tyler Stark
afb3dc0c09 First pass at code quality: adding semicolons. 2014-02-09 20:35:42 -06:00
小太
f9101abbe7 Merge remote-tracking branch 'upstream/master' into tournaments-frontend
Conflicts:
	package.json
2014-02-03 00:24:23 +11:00
Guangcong Luo
1b0b3ec63b Optimize team validator
The main process no longer does any JSON parsing/stringifying of
teams. The communication protocol with validator processes has
been changed from JSON to a string protocol delimited by pipes.

A variety of more minor optimizations have also been done.
2014-01-23 21:35:26 -08:00
小太
250aeb3260 Merge branch 'tournaments' into tournaments-frontend
Conflicts:
	app.js
2013-09-16 16:05:45 +10:00
Guangcong Luo
ae62e9e737 Update ResourceMonitor to control bandwidth 2013-09-01 02:37:35 -07:00
小太
f2f973fe29 Obliterate trailing whitespace 2013-08-18 21:33:15 +10:00
小太
24279166b3 Core file edits to support frontend 2013-08-07 23:22:07 +10:00