Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xat-server 0.1.0 candidate #48

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

Conversation

huumanoid
Copy link
Collaborator

@huumanoid huumanoid commented Oct 12, 2016

Introduction

This pull request introduces a bunch of features which may lead xat-server to becase 0.1.0, according to issue list. Let's discuss all this stuff.

Changes

  • Pools
  • Ranks
  • Compilation
  • Packet builders

Thanks

Thanks @iiegor for his feedback, i was glad to see you are interested in my collaboration.
#1. Pools

Behavior

When user joins pool, it appears online only for users with same pool.
When user changes pool from 0 to 1, users in 0 receive <l>, users in 1 receive <u>.
User sends messages only for users with same pool.
User receives messages only from users with same pool.

Implementation

new method changePool added to chat. This method emit <l>, changes client's onPool and performs joinRoom. Later, while implementing banpool, we should use changePool to put user to banpool. While implementing rankpool, we should add checks to changePool.

Pools tests are into test/pools.coffee.

Issues

Currently, database scheme for chats table doesn't contains onPool field, but it seems that onPool lies into pool field. As for now, it's ok.

TODO

  • Rankpools
  • Dynamic pools

Dynamic pools

Original xat server creates additional pools when amount of online users exceed 50, and connects new users to random additional pools.
#2. Ranks

Ranks handling added:

  • Mainowner's pass, passed by <j2 r="pass"... /> is handled.
  • Permanent rank making implemented (no gconfig)

Behavior

When moderator changes user's rank:

  • user receives <c>, if user is on chat.
  • everyone in same pool receives <m t="/m" p="STR_RANK" .. />.
  • user receives <i> and <gp>, if user is on chat (chat packet builder for <i> and <gp> introduced).
  • others receives <u> with actual user's rank, if user is on chat.

Restrictions:

  • User can't change rank of someone who has greater than or equal rank to user's one.
  • Members and guests can't change ranks.
  • User only can make lower ranks than it has.

Implementation

Ranks stored in ranks table of db, ranks are fetched in chat.joinChat, making handled by chat.makeUser method. Current code assume that only rank data stored in ranks.f. It means, if we want to add more significant bits to ranks.f, we should change at least this line.
Rank data structure added to src/structures/rank.coffee. Implements rank conversions from/to string/number, rank comparison.

Discuss

  • Have I understood ranks.f right? Some insertions into ranks in sql script contains strange values of f (eg 5).
  • client.user.f and client.chat.rank are dependent fields, but they are parts of plain objects. Probably, we should implement class that would contain some logic based on f complex nature.
  • What is Commander? Is it a tool for chat administrator or server administrator? In first case, we only need to add rank checking to solve Triage important tasks #7.

TODO

Compilation task added to package.json.

npm run compile

Output folder is lib.
Binary that runs compiled server: bin/xat-production
To run compiled server, execute:

npm run start-production

Tests uses compiled version of chat. To switch to coffee version instead, change symlink bin/xat-test, which points to server's binary used to tests.
#4. Packet builders

Most of this section content copied from #45
Also, packet builders for chat added.

I've investigated for packet creation methods, which have duplications. I've found, that creation of 'u' packets and 'm' packets for main chat messages are duplicated.
packet-builders/user and packet-builders/message have been created and hardcoded packet composings have been replaced.
I think this stuff will evolve as project grows. Some refactoring needed. For example: may be we should impelement separate method for expanding of 'response-to-locate' packet. May be not.

Discuss

We should implement separate methods for online and offline users.

At first sight, it's convenient to create buildUser method, which can recognize, is user online or not, and make fetch user from db in the second case. However, it requires buildUser to be async. Returning promise from buildUser or even using callback may seems fine, but check out this lines. Here, buildUser should be called in cycle. Making an array of promises and passing them to Promise.all or making recursive calls of callbacks is not the case. That's why sync version of buildUser() have been created.
I think, we can implement unified buildUser method even if there is C# async/await syntax in coffee-script (see ES7 async/await for coffeescript)
#5. Other

@houndci-bot "@ must not be used stand alone"

I propose to ignore this warn. According to coffee-lint docs and coffee-script discussion about standalone @ and this, it's not recommended to use neither standalone @ nor this. But we need to.

database.exec('INSERT INTO messages (id, uid, message, name, registered, avatar, time, pool) values (?, ?, ?, ?, ?, ?, ?, ?)', [ @user.chat, @user.id, message, @user.nickname, @user.username || 'unregistered', @user.avatar, math.time(), @chat.onPool ]).then((data) ->
packet = messageBuilder.buildNewMain(
message: message
client: @

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ must not be used stand alone.

@huumanoid huumanoid changed the title xat-server 0.1.0 candidate xat-server ⬆️0.1.0 candidate Oct 12, 2016
@huumanoid huumanoid changed the title xat-server ⬆️0.1.0 candidate xat-server ⬆️ 0.1.0 candidate Oct 12, 2016
@huumanoid huumanoid changed the title xat-server ⬆️ 0.1.0 candidate xat-server 0.1.0 candidate Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants