Jump to content
  • Advertisement
Sign in to follow this  
kurumi

Idea to make room (channels) for chat server

This topic is 4351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!