-
Notifications
You must be signed in to change notification settings - Fork 1
Client Actions
The gopherClient.connect() function is one of many actions the client can send to the server. Here, I will list all client actions linked to the section that describes it's usage:
-
connect(): Connects the client to the server -
disconnect(): Disconnects the client from the server -
login(): Logs the client in as a User -
logout(): Logs the client out of a User -
signup(): Creates a User account -
changePassword(): Changes the client User's account password -
changeAccountInfo(): Changes one or more client User's custom account info columns -
deleteAccount(): Deletes a User account -
joinRoom(): Makes the client User join an existing room -
leaveRoom(): Makes the client User leave their current room -
createRoom(): Creates a room -
deleteRoom(): Deletes a room created by the client User -
sendInvite(): Sends an invite to another User to the client's private room -
revokeInvite(): Revokes a previously sent invite to the client's private room -
chatMessage(): Sends a chat message to the client User's current room -
privateMessage(): Sends a private message from the client User to another User -
requestFriend(): Sends a friend request from the client User to another User -
acceptFriend(): Accepts a friend request to the client User from another User -
declineFriend(): Declines a friend request to the client User from another User -
removeFriend(): Removes a friend from the client User's friend list -
changeStatus(): Changes the client User's status and sends update to their friends -
setUserVariable(): Sets a single client User's variable -
setUserVariables(): Sets multiple client User's variables -
getUserVariable(): Gets a single client User's variable (API retrieves from RAM, not server) -
customClientAction(): Executes a custom client action on the server
Logging the client in and out is easy. Just use the gopherClient.login() and gopherClient.logout() functions:
gopherClient.login("My Name", "", false, false, null);
gopherClient.logout();
The login() function takes in 5 parameters: userName string, password string, rememberMe boolean, isGuest boolean, and customCols object. The userName parameter accepts a string that logs the client in under that name, and the fourth parameter isGuest logs the user in as a guest. The password, rememberMe, and customCols are used with the SQL features.
logout() takes no parameters and immediately logs the client out from their current User.
When the server is done logging the client in or out, it sends back a response with either a success message or error. You can capture the error and success messages with the events.login and events.logout listeners:
gopherClient.addEventListener(gopherClient.events.login, onLogin);
gopherClient.addEventListener(gopherClient.events.logout, onLogout);
function onLogin(userName, error){
if(error != null){
console.log("Error: [ID - "+error.id+"], [Message - '"+error.m+"']");
}else{
console.log("Logged in as: "+userName);
}
}
function onLogout(success, error){
if(error != null){
console.log("Error: [ID - "+error.id+"], [Message - '"+error.m+"']");
}else{
console.log("You have been logged out");
}
}
If one of these event listeners has an error that is not null, an error occurred while logging in or out. error is an object with id being an integer representing an error ID, and m being a string with a message about what went wrong.
To join a room the client must be logged in, a room to join must exist on the server, and if the room is private, the client User needs to be on the invite list. You can use the joinRoom() and leaveRoom() functions:
gopherClient.joinRoom("roomName");
gopherClient.leaveRoom();
The joinRoom() function takes one parameter, being the name of the room the client wishes to join. leaveRoom() will immediately remove the client from their current room.
Similar to logging in and out, you can make event listeners for joining and leaving rooms with the events.joined and events.left listeners:
gopherClient.addEventListener(gopherClient.events.joined, joinedRoom)
gopherClient.addEventListener(gopherClient.events.left, leftRoom)
function joinedRoom(roomName, error){
if(error != null){
console.log("Error: [ID - "+error.id+"], [Message - '"+error.m+"']");
}else{
console.log("Joined '"+roomName+"'");
}
}
function leftRoom(roomName, error){
if(error != null){
console.log("Error: [ID - "+error.id+"], [Message - '"+error.m+"']");
}else{
console.log("Left '"+roomName+"'");
}
}
If you notice there is lacking information, missing features, or bad explanations, please open an issue. All requests are acceptable and will be taken into consideration, so don't be afraid to ask or report something!