Client

From Crumbled World Wiki

ClientExampleCode

Functions

return function description
bool isConnected() returns true if connected to a server
bool isLosingConnection() returns true if no new messages has been received for the pas 2.5s.
bool isAdmin() returns true if admin of the server
connect(string address) Tries to connect to to the address. address can be like "localhost","192.168.1.2". The connection attemps will be done in a seperate thread
disconnect() Disconnects from the server
{ {ping=int(), clientId=int(),

playerId=int(), name=string()} }

getConnected() returns a table with all that is connected like {[1]="client1", [2]="client2"}
string getWhyNotConnected() returns a string with the reason why the client is not connected anymore.
string getUserName() Returns the name for this client, is also what will be shown to other players
int getPlayerId() Returns the player id for the client. Is used for who owns what in multiplayer, this id can be changed.
int getClientId() Returns a constant id that the server is using to identify you.
bool isPlayerIdInUse(int id) Returns true if the player id is in use
int getConnectedPlayerCount() Returns the numbers of players.
double getPing() Returns the RTT.
setUserName(string userName) Sets the username and inform the server.
requestPlayerId(int playerId) Sends a request to the server for a playerId.
bool hasConnectedUsersChanged() returns true if somone has connected to the server or disconnected
bool hasMessage() returns true if there is a message in the queue to be popped
string popMessage() Returns the message in queue. or "" if none is available
write(string msg) Write a message to all other connected clients. Delivery is not guaranteed
writeSafe(string msg) Write a message to all other connected clients. Message is guaranteed to be delivered but not in order
sendFile(int toClientId, string file) sends a file to a client
{string()} getDowloadedFiles() return a list of all downloaded files to there local file path. the file list is cleared after each call.
number getDownloadPercentage() return the download percentage status, is the average of all downloads.
number getSendingPercentage() return the upload percentage status, is the average of all uploads.
bool isDownloadingFiles() return true if we are downloading any file
bool isSendingFiles() return true if we are uploading any file