Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 667 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Whois Online #143845
07/27/07 16:06
07/27/07 16:06
Joined: Apr 2006
Posts: 1,551
Netherlands
D3D Offline OP
Serious User
D3D  Offline OP
Serious User

Joined: Apr 2006
Posts: 1,551
Netherlands
I'm trying to create a Whois Online for the Lite-C chat. So when a player connects this will show his/her name in a list. Now I got it working by breaking down the chat code. Only there is a problem: When a new player connects he/she doesn't see the already connected players only his/her own name and anyone that connects after that.

How must I send the names of the players already logged on the server to the new client?

online.c
Code:
// Whois Online

#include <acknex.h>
#include <default.c>
#include "uscroll.c";

//////////////////////////////////////////////////////////////////////////////////
// DEFINES
#define MAX_CONNECTIONS 8

//////////////////////////////////////////////////////////////////////////////////
// STRINGS

STRING* MyAppTitle = "Whois Online";

//////////////////////////////////////////////////////////////////////////////////
// FONTS
FONT* arial_font = "Arial#20b";

//////////////////////////////////////////////////////////////////////////////////
// VARIABLES

//////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS

function startup()
{
PlayerNameCombine();
on_client = GetPlayerName;
on_server = ServerGetSendPlayerName;
}

function main()
{
fps_max = 60;
video_mode = 6;

//d3d_autotransparency = ON;

video_window(vector(375,350,0),NULL,112,MyAppTitle);
level_load("");
wait(2);
startup();
}



uscroll.c
Code:
#include <acknex.h>

FONT* std_font = "ackfont.pcx";

STRING* receive_PlayerName="#20";
STRING* send_PlayerName = "#20";

STRING* uname1 = "#20";
STRING* uname2 = "#20";
STRING* uname3 = "#20";
STRING* uname4 = "#20";
STRING* uname5 = "#20";
STRING* uname6 = "#20";
STRING* uname7 = "#20";
STRING* uname8 = "#20";

TEXT* txtPlayerName =
{
strings=5;
string=uname1,uname2,uname3,uname4,uname5,uname6,uname7,uname8;
pos_x=300;
pos_y=250;
layer=2;
font=std_font;
flags=visible;
}

function PlayerNameCombine()
{
// Prepare the PlayerName
str_cpy(send_PlayerName, player_name);

// Send the PlayerName
send_string_to(NULL, send_PlayerName); // Client send PlayerName -> Server
wait(1);

str_cpy(send_PlayerName,"#20"); // Now empty the string
}

function GetPlayerName() // Data Client -> Server
{
wait(1); // Wait until there is a new name otherwise the string is empty
#ifndef server // To prevent the server receive the PlayerName twice

if(str_len(receive_PlayerName)>0) // When there is a new PlayerName
{
// Organize PlayerNames

str_cpy(uname1,uname2);
str_cpy(uname2,uname3);
str_cpy(uname3,uname4);
str_cpy(uname4,uname5);
str_cpy(uname5,uname6);
str_cpy(uname6,uname7);
str_cpy(uname7,uname8);
str_cpy(uname8,receive_PlayerName);

wait(1);

str_cpy(receive_PlayerName,"#20"); // Empty string
}

#endif // Don't forget to close the ifndef ifdef

#ifdef server
wait(1); // Because it's a empty function give the server something to do
#endif
}

function ServerGetSendPlayerName() // Data Server -> To all Clients
{
/* if((event_type == EVENT_JOIN) || (event_type == EVENT_LEAVE))
{return;} */

wait(1); // Wait until there is a PlayerName
if(str_len(send_PlayerName)>0)
{
// Copy
str_cpy(receive_PlayerName,send_PlayerName);

// Organize PlayerNames

str_cpy(uname1,uname2);
str_cpy(uname2,uname3);
str_cpy(uname3,uname4);
str_cpy(uname4,uname5);
str_cpy(uname5,uname6);
str_cpy(uname6,uname7);
str_cpy(uname7,uname8);
str_cpy(uname8,receive_PlayerName);

// Don't empty strings just yet
// Send to all clients

send_string_to(NULL,receive_PlayerName); // Execute as Server and send string to all Clients
wait(1);

str_cpy(receive_PlayerName,"#20"); // Now empty the strings
str_cpy(send_PlayerName,"#20");
}
}




smile
Re: Whois Online [Re: D3D] #143846
07/27/07 23:44
07/27/07 23:44
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
can't you store them on the server and then in the event of a player connecting to the chat send them to the just connected player?


BASIC programmers never die, they GOSUB and don't RETURN.
Re: Whois Online [Re: bstudio] #143847
07/28/07 13:49
07/28/07 13:49
Joined: Apr 2006
Posts: 1,551
Netherlands
D3D Offline OP
Serious User
D3D  Offline OP
Serious User

Joined: Apr 2006
Posts: 1,551
Netherlands
Yeah I somewhat tried that, but hoped to use this code instead. Don't know how save it is to store the names in files. Because what if the users hangs or breaks his/her connection not the normal way. The name might stay in the file or even crash the server if not programmed the right way.


smile

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1