thestuckster / pokemonBotDown

0 stars 0 forks source link

Handle misc. battle messages #8

Closed ghost closed 8 years ago

ghost commented 8 years ago

Handles the following battle messages: j, l, gametype, gen, tier, seed, rule

SpenceSellers commented 8 years ago

Sweet! I've been wondering the whole time if the methods on battle that are called because of Battle Messages should be named like start() or if it should be clearer who's supposed to call it, like handleStart() or onStart().

Eventually I decided not to special-case the methods called by handleBattleMessage, but they're not necessarily supposed to be user-facing either, so ???

ghost commented 8 years ago

Yeah, I feel like some of this logic should be moved to battle.js

SpenceSellers commented 8 years ago

Nah, I think that everything to do with the protocol should stay in the protocol code. If it gets split off, it should just be to a battleMessage.js or something.

Also I like the argument destructuring you're doing in the handlers. I didn't actually know that that worked yet...

ghost commented 8 years ago

I didn't really know you could do it either. It's what I naturally do in Elixir and it just didn't crash lol

SpenceSellers commented 8 years ago

Yeah, I think I didn't know about it because it's not included in many ES6 tutorials yet, because it's VERY iffy on real browsers. Luckily we don't have to care.

ghost commented 8 years ago

@SpenceSellers

According to the docs, there are several battle messages that can have multiple representations:

For bandwidth reasons, five of the message types - chat, join, leave, name, and battle - are sometimes abbreviated to c, j, l, n, and b respectively. All other message types are written out in full so they should be easy to understand.

Four of these can be uppercase: J, L, N, and B, which are the equivalent of their lowercase versions, but are recommended not to be displayed inline because they happen too often. For instance, the main server gets around 5 joins/leaves a second, and showing that inline with chat would make it near-impossible to chat.

So we need to handle j, J, and join when someone joins the room. Is there a better way to do this other than adding more entries to battleHandlers?

ghost commented 8 years ago

We could do something like this at pokemonClient.js:173:

const first = normalizeCommand(pieces[1]);

normalizeCommand would be some new function that would take in something like j or L and transform it to the full verb join or leave.

ghost commented 8 years ago

It also looks like there is a Set in javascript? I've never seen that before, but we should use that for spectators instead of the keys of an object.

SpenceSellers commented 8 years ago

I'm actually secretly using a Set down here!

The normalize thing sounds like a good idea. The the other alternative is to pull out the affected handlers into seperate functions, and have parts of the handler object look like {'j': handleJoin, 'join': handleJoin, ....

I think your solution is more appealing.

ghost commented 8 years ago

Normalizing chat commands handles here: 9ef8143