Sign in to follow this  
bahn

My first question

Recommended Posts

I'll try to explain as best I can, I'm working on a MUD (server side) telnet as client, i'd like to have a "Concurrent User" Count on the server (console app) This is where I run into trouble, Since if I want it to read 0 all the time, I can leave it out of any loop's. However, if I want it to be "real time" I have to loop it, and the way i have it setup right now is cout << "Current Connections: " << ClientsConnected << endl; As you can imagine, in a loop statement.. It spam's the .. out of said console. Now instead of updating it every ten minutes. or setting it so i can type /user or something.. Is there absolutetly no way for me to simply update an integer, instead of creating an entirely new line each and every time? Thank's for any response, insight, idea's, Anything. I've asked quite a few friends and none of them have responded with anything. :P

Share this post


Link to post
Share on other sites
There is no standard way of doing it. If you specify what API and environment you are targeting (Win32, some *nix with libcurses ...), I'm sure someone here can help you further.

Share this post


Link to post
Share on other sites
Currently it's running under a Windows Environment, However I hope it to be port-able to linux in the future (If I need it to be, Since obviously my home box isn't very 'stable'.)

Share this post


Link to post
Share on other sites
About spamming the console. I'm not super familiar with console programs. But you might want to consider giving the game a graphical window interface. Just have a label that tells how many people are online, and update the label. Won't spam the console.

maybe you could have a global integer and set it's value equal to ClientsConnected. Then, whenever someone logs in out out, that global variable is increased or decreased. Maybe every 10 minutes you could reset the global equal to ClientsConnnected just to make sure it is still accurate.

Share this post


Link to post
Share on other sites
you could store it in a log file and you should also only have it add a "clients connected" message each time a client connects, not every x seconds

Share this post


Link to post
Share on other sites
I think I'm misunderstanding your problem. Why not just retrieve the information when you need it? Don't keep polling for it 500 times per second in a loop.

Some C# pseudocode:


public class Server
{
private SortedList<User> m_Users;

public int UserCount
{
get
{
return this.m_Users.Count;
}
}
}


If you want to be notified when m_Users changes, have a callback function that gets called each time the client count changes. Then you can have the program output something like "New client connected. Total users: 41" or "Client disconnected. Total users: 40".

Share this post


Link to post
Share on other sites
kSquared has good advice. Even once you have "writing to the same position on the screen" working, you should avoid polling, to avoid CPU drain.

What you want to do is send an "update" message to every connected user, each time *that set of users changes*. For example, as part of the code that handles the (dis)connection. Or by registering some callbacks or whatever.

Anyway. Since your "API and environment" is "telnet", methinks this will be of interest. Most Telnet clients will offer support for such codes (which you just embed into the text data you send out).

Share this post


Link to post
Share on other sites
Awesome everyone, Thank's.

As for some responses...:
ShiningBlue: I already sorta played with a Widnows API and to be frank it "owned" me, I had nothing but trouble trying to setup just simple text, etc. I think windows programming is above me at the moment, and all my friends dont really know Windows programming, so It's really been hard - thus i decided to leave the server program is console, doesn't really need to be all that fancy afterall..

kSquared: I used your idea, your a genius - Thanks.
Roboguy: Yah, I didn't like looping it, but like I said - I wanted it to be a realtime integer.
Zahlman: I know good advice when I see it ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this