Idea to make room (channels) for chat server

Started by
6 comments, last by kurumi 17 years, 10 months ago
I have a chat server in c++ and i am going to add rooms to this chat server so when a user connects the server if he types something like "Join #blablaroom" he will be directed to this blablaroom...Any idea to code it?
Advertisement
Here's one idea:

1) keep data structure of which users are in what rooms

2) everytime you receive a chat message, iterate over the rooms that the user is in, and send the message to all other users in that room
enum Bool { True, False, FileNotFound };
Thanks for answering my question...But the problem is that how can i make rooms at first...Do you think i should make an array for this?
I think what you need is a master server. You already have a chat server, that clients can connect to. Now you need a server that manages multiple chat servers (think master servers for games: where the lobbies connect to the master server and clients search for and connect to lobbies). Adapt you chat server code, to only communicate wiht lobbies and lobby requests (ex: give me list of lobbies). Keep all your lobbies on the master server in an array or vector and if the lobbies do not send a keep alive packet every x mins, then destroy the lobby from the master server. If clients want to connetc to a lobby, they will already have the ip address from the lobby list request and can connect to the chat lobby themselves. This way, people can post chat lobby servers from your master server and use thier own machine for the overhead.
I got your idea but i got stuck with how to put lobbies in the array...Can you give me an example for this?Can you give me a working example for this?
  struct Chatroom;  struct User {    std::string username;    std::vector<Chatroom *> rooms;  };  struct Chatroom {    std::string name;    std::vector<User *> users;  };  std::map<std::string, Chatroom *> chatrooms;  Chatroom * FindOrMakeChatroom(std::string name) {    std::map<std::string, Chatroom *>::iterator ptr = chatrooms.find(name);    if (ptr != chatrooms.end()) return (*ptr).second;    Chatroom r;    r.name = name;    chatrooms[name] = r;    return &chatrooms[name];  }


This has absolutely nothing to do with network programming, though; I'm moving your question to For Beginners as it's a pretty basic data structure question.
enum Bool { True, False, FileNotFound };
Data structure questions go here.
enum Bool { True, False, FileNotFound };
Thanks for help!lol

This topic is closed to new replies.

Advertisement