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.cCode:
// 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.cCode:
#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");
}
}