From 729209288d4a702ba1dee0418585bb338fb21626 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 28 Oct 2018 23:15:40 +1100 Subject: [PATCH] Created an empty shell of a server --- .envdev | 1 + ADAM/adam.js | 2 +- ADAM/core.js | 238 ++++++++++++++++++------------------- ADAM/package.json | 2 +- ADAM_CptMon/adam-cptmon.js | 3 +- ADAM_CptMon/package.json | 2 +- ADAM_Dairo/adam-dairo.js | 3 +- ADAM_Dairo/package.json | 2 +- ADAM_Kamala/adam-kamala.js | 3 +- ADAM_Kamala/package.json | 2 +- Librarian/package.json | 2 +- SERVER_City/city.js | 113 +++++++++++++++++- SERVER_City/package.json | 20 ++++ Shared/data_request.js | 24 ++-- Shared/factions.js | 38 +++--- Shared/package.json | 6 +- Shared/progression.js | 23 ++-- 17 files changed, 299 insertions(+), 185 deletions(-) create mode 100644 SERVER_City/package.json diff --git a/.envdev b/.envdev index adc3420..2c9c61e 100644 --- a/.envdev +++ b/.envdev @@ -82,3 +82,4 @@ RANK_3_THRESHOLD=30 # Server SERVER_ADDRESS="http://127.0.0.1" SERVER_PASS_KEY="" +SERVER_PORT="4500" diff --git a/ADAM/adam.js b/ADAM/adam.js index 63ec612..afd8cb6 100644 --- a/ADAM/adam.js +++ b/ADAM/adam.js @@ -60,7 +60,7 @@ client.on('ready', async () => { console.log("Logged in as: " + client.user.username + " - " + client.user.id); //ADAM updates stamina (1) and health by 1% every 2 min. - cron.schedule('*/2 * * * *', () => { + cron.schedule('*/2 * * * *', () => { //TODO: move this to Mori console.log('Updating STAMINA every 2 min.'); shared.SendServerData("updateStamina"); }); diff --git a/ADAM/core.js b/ADAM/core.js index a00694f..c0681bd 100644 --- a/ADAM/core.js +++ b/ADAM/core.js @@ -3,7 +3,6 @@ exports = module.exports = {}; let dataRequest = require("../Shared/data_request"); let discord = require('discord.js'); let shared = require("../Shared/shared"); -let calcRandom = require('../Shared/calc_random'); //ProcessGameplayCommands //client - discord.js client @@ -17,66 +16,15 @@ exports.ProcessGameplayCommands = function(client, message, dialog) { switch (command) { case "checkin": - let checkinAmount = calcRandom.Random(4, 9); - let checkInResponse = String(dataRequest.SendServerData("checkin", message.author.id, checkinAmount)); - if (checkInResponse === "available") { - shared.SendPublicMessage(client, message.author, message.channel, dialog("checkin", checkinAmount)); - shared.AddXP(client, message.author, 1); //1XP - exports.HandleLevelUp(client, message.member, message.channel, dialog); - } else { - shared.SendPublicMessage(client, message.channel, dialog("checkinLocked", message.author.id, checkInResponse)); - } + exports.ProcessCheckinCommand(client, message.member, message.channel, dialog); return true; - case "give": //TODO: fold this code into a function - let amount = Math.floor(parseFloat(args[0])); - - if (isNaN(amount)) { - shared.SendPublicMessage(client, message.channel, dialog("giveFailed", message.author.id)); - return true; - } - - //not enough - if (amount <= 0) { - shared.SendPublicMessage(client, message.channel, dialog("giveNotAboveZero", message.author.id)); - return true; - } - - //didn't mention anyone - if (message.mentions.members.size == 0) { - shared.SendPublicMessage(client, message.channel, dialog("giveInvalidUser", message.author.id)); - return true; - } - - let targetMember = message.mentions.members.first(); - - //can't give to yourself - if (targetMember.id === message.author.id) { - shared.SendPublicMessage(client, message.channel, dialog("giveInvalidUserSelf", message.author.id)); - return true; - } - - let accountBalance = dataRequest.LoadServerData("account", message.author.id); - - //not enough money in account - if (accountBalance < amount) { - shared.SendPublicMessage(client, message.channel, dialog("giveNotEnoughInAccount", message.author.id)); - return true; - } - - //try to send the money - if (dataRequest.SendServerData("transfer", message.author.id, targetMember.id, amount) != "success") { - shared.SendPublicMessage(client, message.channel, dialog("giveFailed", message.author.id)); - return true; - } - - //print the success message - shared.SendPublicMessage(client, message.author, message.channel, dialog("giveSuccessful", targetMember.id, amount)); + case "give": + exports.ProcessGiveCommand(client, message, args, dialog); return true; case "stats": exports.ProcessStatsCommand(client, message.member, message.channel, dialog); - return true; } @@ -92,29 +40,102 @@ exports.ProcessGameplayCommands = function(client, message, dialog) { //factionShorthand - the shorthand name of the new faction (TEMPORARY) exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dialog, factionShorthand) { //tailor this for each faction leader? - shared.ChangeFaction(client, factionRole, message.channel, message.member) - .then(result => { - switch (result) { - case "alreadyJoined": - shared.SendPublicMessage(client, message.channel, dialog("alreadyJoined" + factionShorthand, message.author.id)); - break; - case "hasConvertedToday": - shared.SendPublicMessage(client, message.channel, dialog("conversionLocked", message.author.id)); - break; - case "createdUser": - shared.SendPublicMessage(client, message.author, shared.GetFactionChannel(factionRole), dialog("newUserPublicMessage", shared.GetFactionName(factionRole), shared.GetFactionChannel(factionRole))); - shared.SendPrivateMessage(client, message.author, dialog("newUserPrivateMessage", dialog("newUserPrivateMessageRemark" + factionShorthand))); - break; - case "joined": - shared.SendPublicMessage(client, message.author, message.channel, dialog("join" + factionShorthand)); - break; - default: - //DEBUGGING - console.log("processFactionChangeAttempt failed:" + result); + let handleResponse = async function(response) { + switch (response) { + case "alreadyJoined": + shared.SendPublicMessage(client, message.channel, dialog("alreadyJoined" + factionShorthand, message.author.id)); + break; + case "conversionLocked": + shared.SendPublicMessage(client, message.channel, dialog("conversionLocked", message.author.id)); + break; + case "newUser": + shared.SendPublicMessage(client, message.author, shared.GetFactionChannel(factionRole), dialog("newUserPublicMessage", shared.GetFactionName(factionRole), shared.GetFactionChannel(factionRole))); + shared.SendPrivateMessage(client, message.author, dialog("newUserPrivateMessage", dialog("newUserPrivateMessageRemark" + factionShorthand))); + break; + case "joined": + shared.SendPublicMessage(client, message.author, message.channel, dialog("join" + factionShorthand)); + break; + default: + //DEBUGGING + console.log("processFactionChangeAttempt failed:" + result); + } + } + + shared.ChangeFaction(client, factionRole, message.channel, message.member, handleResponse); +} + +//ProcessStatsCommand +//client - discord.js client +//member - discord.js member +//channel - discord.js channel +//dialog - dialog function +exports.ProcessCheckinCommand = function(client, member, channel, dialog) { + let handleResponse = function(checkinResponse, checkinAmount) { + if (checkinResponse === "available") { + shared.SendPublicMessage(client, member.user, channel, dialog("checkin", checkinAmount)); + exports.HandleLevelUp(client, member, channel, dialog); + } else { + shared.SendPublicMessage(client, channel, dialog("checkinLocked", member.user.id, checkinResponse)); + } + } + + dataRequest.OnServerData("checkin", handleResponse, member.user.id); //ID of the person who checked in TODO: username too +} + +//ProcessStatsCommand +//client - discord.js client +//message - discord.js message +//args - arguments to the give command +//dialog - dialog function +exports.ProcessGiveCommand = function(client, message, args, dialog) { + let amount = Math.floor(parseFloat(args[0])); + + if (isNaN(amount)) { + shared.SendPublicMessage(client, message.channel, dialog("giveFailed", message.author.id)); + return; + } + + //not enough + if (amount <= 0) { + shared.SendPublicMessage(client, message.channel, dialog("giveNotAboveZero", message.author.id)); + return; + } + + //didn't mention anyone + if (message.mentions.members.size == 0) { + shared.SendPublicMessage(client, message.channel, dialog("giveInvalidUser", message.author.id)); + return; + } + + let targetMember = message.mentions.members.first(); + + //can't give to yourself + if (targetMember.id === message.author.id) { + shared.SendPublicMessage(client, message.channel, dialog("giveInvalidUserSelf", message.author.id)); + return; + } + + let handleResponse = function(accountBalance) { + //not enough money in account + if (accountBalance < amount) { + shared.SendPublicMessage(client, message.channel, dialog("giveNotEnoughInAccount", message.author.id)); + return; + } + + //try to send the money + let handleResponse = function(response) { + if (response !== "success") { + shared.SendPublicMessage(client, message.channel, dialog("giveFailed", message.author.id)); + } else { + //print the success message + shared.SendPublicMessage(client, message.author, message.channel, dialog("giveSuccessful", targetMember.id, amount)); } - }) - .catch(console.error); - return true; + } + + dataRequest.OnServerData("transfer", handleResponse, message.author.id, targetMember.id, amount); + } + + dataRequest.OnServerData("account", handleResponse, message.author.id); } //ProcessStatsCommand @@ -124,49 +145,21 @@ exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dia //dialog - dialog function exports.ProcessStatsCommand = function(client, member, channel, dialog) { exports.HandleLevelUp(client, member, channel, dialog); - let stats = exports.GetStats(member.user); - exports.PrintStats(client, member, channel, stats); + exports.GetStats(member.user, (stats) => { + exports.PrintStats(client, member, channel, stats); + }); } //GetStats //user - discord.js user OR username -exports.GetStats = function(user) { //Grabs all parameters from server +//fn - function to pass the stats to +exports.GetStats = function(user, fn) { //handle user strings if (typeof(user) === "string") { user = client.users.find(item => item.username === user || item.id === user); } - let userStatsResponse = String(dataRequest.LoadServerData("userStats", user.id)).split(","); - - if (userStatsResponse[0] == "failure") { - throw "server returned an error to userStats request"; - } - - let strength = parseFloat(userStatsResponse[1]); //TODO: constants representing the player structure instead of [0] - let speed = parseFloat(userStatsResponse[2]); - let stamina = parseFloat(userStatsResponse[3]); - let health = parseFloat(userStatsResponse[4]); - let maxStamina = parseFloat(userStatsResponse[5]); - let maxHealth = parseFloat(userStatsResponse[6]); - let wallet = parseFloat(userStatsResponse[7]); - let experience = parseFloat(userStatsResponse[8]); - let level = Math.floor(parseFloat(userStatsResponse[9])); - let levelPercent = parseFloat(userStatsResponse[10]); - let statPoints = parseFloat(userStatsResponse[11]); - - return { - strength: strength, - speed: speed, - stamina: stamina, - health: health, - maxStamina: maxStamina, - maxHealth: maxHealth, - wallet: wallet, - experience: experience, - level: level, - levelPercent: levelPercent, - statPoints: statPoints - }; + dataRequest.OnServerData("userStats", fn, user.id); } //PrintStats @@ -229,19 +222,16 @@ exports.HandleLevelUp = function(client, member, channel, dialog) { } // Sees if the user is supposed to level up - let [levelUpResponse, level, statPoints] = shared.LevelUp(client, member); - - //handle channel strings - if (typeof(channel) === "string") { - channel = client.channels.find(item => item.name === channel || item.id === channel); - } - - //handle levelling up - if (levelUpResponse === "levelUp" || levelUpResponse === "RankUp") { - if (level >= process.env.RANK_3_THRESHOLD) { - shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), level)); - } else { - shared.SendPublicMessage(client, member.user, channel, dialog("LevelUp", dialog("levelUpRemark"), level, statPoints)); + let handleResponse = function(response, level, statPoints) { + //handle levelling up + if (response === "levelUp" || response === "RankUp") { + if (level >= process.env.RANK_3_THRESHOLD) { + shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), level)); + } else { + shared.SendPublicMessage(client, member.user, channel, dialog("LevelUp", dialog("levelUpRemark"), level, statPoints)); + } } } + + shared.LevelUp(client, member, handleResponse); } \ No newline at end of file diff --git a/ADAM/package.json b/ADAM/package.json index 24ad0ae..81d2d77 100644 --- a/ADAM/package.json +++ b/ADAM/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-elasticbeanstalk", + "name": "ADAM", "version": "1.0.0", "description": "", "main": "server.js", diff --git a/ADAM_CptMon/adam-cptmon.js b/ADAM_CptMon/adam-cptmon.js index f482ef4..bfae93a 100644 --- a/ADAM_CptMon/adam-cptmon.js +++ b/ADAM_CptMon/adam-cptmon.js @@ -108,7 +108,8 @@ function processBasicCommands(client, message) { return true; case "genesis": - return core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_B_ROLE, dialog, "Genesis"); + core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_B_ROLE, dialog, "Genesis"); + return true; //ADAM and the faction leaders print the intros in the gate case "introgenesis": diff --git a/ADAM_CptMon/package.json b/ADAM_CptMon/package.json index 549469a..4a6bd97 100644 --- a/ADAM_CptMon/package.json +++ b/ADAM_CptMon/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-elasticbeanstalk", + "name": "ADAM_CptMon", "version": "1.0.0", "description": "", "main": "server.js", diff --git a/ADAM_Dairo/adam-dairo.js b/ADAM_Dairo/adam-dairo.js index bac002c..2cc1a75 100644 --- a/ADAM_Dairo/adam-dairo.js +++ b/ADAM_Dairo/adam-dairo.js @@ -108,7 +108,8 @@ function processBasicCommands(client, message) { return true; case "hand": - return core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_C_ROLE, dialog, "Hand"); + core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_C_ROLE, dialog, "Hand"); + return true; //ADAM and the faction leaders print the intros in the gate case "introhand": diff --git a/ADAM_Dairo/package.json b/ADAM_Dairo/package.json index ad18cf0..3272e7d 100644 --- a/ADAM_Dairo/package.json +++ b/ADAM_Dairo/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-elasticbeanstalk", + "name": "ADAM_Dairo", "version": "1.0.0", "description": "", "main": "server.js", diff --git a/ADAM_Kamala/adam-kamala.js b/ADAM_Kamala/adam-kamala.js index b6bd839..cc5ecd3 100644 --- a/ADAM_Kamala/adam-kamala.js +++ b/ADAM_Kamala/adam-kamala.js @@ -108,7 +108,8 @@ function processBasicCommands(client, message) { return true; case "obsidian": - return core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_A_ROLE, dialog, "Obsidian"); + core.ProcessFactionChangeAttempt(client, message, process.env.GROUP_A_ROLE, dialog, "Obsidian"); + return true; //ADAM and the faction leaders print the intros in the gate case "introobsidian": diff --git a/ADAM_Kamala/package.json b/ADAM_Kamala/package.json index bff6317..2e4b6c0 100644 --- a/ADAM_Kamala/package.json +++ b/ADAM_Kamala/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-elasticbeanstalk", + "name": "ADAM_Kamala", "version": "1.0.0", "description": "", "main": "server.js", diff --git a/Librarian/package.json b/Librarian/package.json index 2bc7dd6..5153fb9 100644 --- a/Librarian/package.json +++ b/Librarian/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-elasticbeanstalk", + "name": "Librarian", "version": "1.0.0", "description": "", "main": "server.js", diff --git a/SERVER_City/city.js b/SERVER_City/city.js index ae15243..d5bf016 100644 --- a/SERVER_City/city.js +++ b/SERVER_City/city.js @@ -1,3 +1,114 @@ // .env Variables -require('dotenv').config({path: '../.env'}); +require("dotenv").config({path: "../.env"}); +//server tools +let express = require("express"); +let socket = require("socket.io"); + +//express setup +let app = express(); +let server = app.listen(process.env.SERVER_PORT, () => { + console.log("Listening to requests on port " + process.env.SERVER_PORT); +}); + +//shared code +let calcRandom = require('../Shared/calc_random'); + +//socket.io setup +let io = socket(server); + +//TODO: isolate these responses to specific bots +io.on("connection", async (socket) => { + console.log("made socket connection"); + + //update the playerbase's stamina on command + socket.on("updateStamina", async ({ userID, data }) => { + console.log("updating stamina for all users..."); + //TODO: update the stamina + }); + + //handle checkin + socket.on("checkin", async ({ data }, fn) => { + console.log("received a checkin request..."); + //TODO: handle checkins (grant crystal bonus) + //TODO: handle XP (grant 1 XP) + + if (fn) { + fn("available", calcRandom.Random(4, 9)); //TODO: ["available", time since last checkin], randomAmount + } + }); + + //handle account requests + socket.on("account", async ({ data }, fn) => { + console.log("received an account request..."); + //data[0] = ID of the person to check + + if (fn) { + fn(0); //TODO: accountBalance + } + }); + + //handle transfering data between accounts + socket.on("transfer", async ({ data }, fn) => { + console.log("received a transfer request..."); + //data[0] = ID of the source account + //data[1] = ID of the destination account + //data[2] = amount to send + + if (fn) { + fn("failure"); //TODO: ["success", "failure"] + } + }); + + //handle the user stats + socket.on("userStats", async ({ data }, fn) => { + console.log("received a userStats request..."); + //data[0] = user ID + + //NOTE: build a temporary structure to pass back + let stats = { + strength: 0, + speed: 0, + stamina: 0, + health: 0, + maxStamina: 0, + maxHealth: 0, + wallet: 0, + experience: 0, + level: 0, + levelPercent: 0, + statPoints: 0 + }; + + if (fn) { + fn(stats); + } + }); + + //DEBUGGING? + socket.on("addXP", async ({ userID, data }) => { + console.log("received an addXP request..."); + //data[0] = amount + + //TODO: add an amount of XP to a user account + }); + + //handle levelling up + socket.on("levelUp", async ({ data }, fn) => { + console.log("received a levelUp request..."); + //data[0] = user ID + + if (fn) { + fn("none", 0, 0); //["none", "levelUp"], level, statPoints + } + }); + + socket.on("conversion", async ({ data }, fn) => { + console.log("received a conversion request..."); + //data[0] = user ID + + if (fn) { + fn("newUser"); //["joined", "conversionLocked", "newUser"] + } + }); +}); \ No newline at end of file diff --git a/SERVER_City/package.json b/SERVER_City/package.json new file mode 100644 index 0000000..8f53d47 --- /dev/null +++ b/SERVER_City/package.json @@ -0,0 +1,20 @@ +{ + "name": "server_city", + "version": "1.0.0", + "description": "", + "main": "city.js", + "scripts": { + "start": "forever -o forever.log -e error.log start city.js", + "restart": "forever -o forever.log -e error.log restart city.js", + "stop": "forever stop city.js", + "node": "node city.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "dotenv": "^6.1.0", + "express": "^4.16.4", + "forever": "^0.15.3", + "socket.io": "^2.1.1" + } +} diff --git a/Shared/data_request.js b/Shared/data_request.js index f88280c..9adbc78 100644 --- a/Shared/data_request.js +++ b/Shared/data_request.js @@ -2,16 +2,22 @@ exports = module.exports = {}; require("dotenv").config({path: "../.env"}); -let request = require("sync-request"); -exports.LoadServerData = function(dataType, usersID = "") { - let response = request("GET", `${process.env.SERVER_ADDRESS}/getData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}`); -// console.log(response.getBody()); - return response.getBody(); +//socket tools +let io = require("socket.io-client")(`${process.env.SERVER_ADDRESS}:${process.env.SERVER_PORT}`); + +//SendServerData +//dataType - the type of data being sent +//userID (optional) - the id of the user to be bundled with the data +//...data (optional) - any data you wish to send +exports.SendServerData = function(dataType, userID = "", ...data){ + io.emit(dataType, { userID: userID, data: data }); } -exports.SendServerData = function(dataType, usersID = "", dataToSend="", dataToSend2 = ""){ - let response = request("GET", `${process.env.SERVER_ADDRESS}/sendData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}&dataToSend=${dataToSend}&dataToSend2=${dataToSend2}`); -// console.log(response.getBody()); - return response.getBody(); +//OnServerData +//dataType - the type of data being sent and received +//fn (optional) - the aknowledgement function that is called on the other end (takes the result as an argument) +//...data (optional) - any data you wish to send +exports.OnServerData = function(dataType, fn, ...data) { + io.emit(dataType, { data: data }, fn); } diff --git a/Shared/factions.js b/Shared/factions.js index bee49b7..4cbd18b 100644 --- a/Shared/factions.js +++ b/Shared/factions.js @@ -58,7 +58,7 @@ exports.GetFactionChannel = function(factionRole) { //factionRole - a faction role //channel - discord.js channel OR channel name //member - discord.js member -exports.ChangeFaction = async function(client, factionRole, channel, member) { +exports.ChangeFaction = function(client, factionRole, channel, member, fn) { //factionRole must be a faction role if (!exports.CheckFaction(factionRole)) { throw "factionRole is not a faction!"; @@ -79,31 +79,23 @@ exports.ChangeFaction = async function(client, factionRole, channel, member) { if (member.roles.has(factionRole)) { //can't change to this faction - return "alreadyJoined"; + fn("alreadyJoined"); } - if (dataRequest.LoadServerData("hasConvertedToday", member.user.id) == 1) { - //can't change too fast - return "hasConvertedToday"; - } + let handleResponse = async function(response) { + if (response === "conversionLocked") { //can't change too fast + fn(response); + return; + } - //Creates a new user - var newUserResponse = String(dataRequest.SendServerData("newUser", member.user.id, "New user.")); + //joins the new faction + await member.removeRole(process.env.GROUP_A_ROLE); + await member.removeRole(process.env.GROUP_B_ROLE); + await member.removeRole(process.env.GROUP_C_ROLE); + await member.addRole(factionRole); - //joins the new faction - await member.removeRole(process.env.GROUP_A_ROLE); - await member.removeRole(process.env.GROUP_B_ROLE); - await member.removeRole(process.env.GROUP_C_ROLE); - await member.addRole(factionRole); + fn(response); + }; - //send the server the info (for logging) - dataRequest.SendServerData("conversion", member.user.id, "Converted to " + exports.GetFactionName(factionRole)); - - if (newUserResponse === "createdUser") { - //send the private welcoming message - return newUserResponse; - } else { - //send the public welcoming message - return "joined"; - } + dataRequest.OnServerData("conversion", handleResponse, member.user.id); } diff --git a/Shared/package.json b/Shared/package.json index 8e1ade5..f010552 100644 --- a/Shared/package.json +++ b/Shared/package.json @@ -1,8 +1,8 @@ { - "name": "shared", + "name": "Shared", "version": "1.0.0", "description": "", - "main": "calc_random.js", + "main": "shared.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -10,6 +10,6 @@ "license": "ISC", "dependencies": { "dotenv": "^6.1.0", - "sync-request": "^6.0.0" + "socket.io-client": "^2.1.1" } } diff --git a/Shared/progression.js b/Shared/progression.js index 53a1a0f..c74f7f0 100644 --- a/Shared/progression.js +++ b/Shared/progression.js @@ -18,7 +18,8 @@ exports.AddXP = function(client, user, amount) { //LevelUp //client - discord.js client //member - member to get the level up -exports.LevelUp = function(client, member) { //NOTE: why is this called separately? +//fn - function to pass the result to +exports.LevelUp = function(client, member, fn) { //handle member strings if (typeof(member) === "string") { //get the member @@ -32,22 +33,12 @@ exports.LevelUp = function(client, member) { //NOTE: why is this called separate if (client.user.username == process.env.GROUP_B_LEADER_NAME && !member.roles.has(process.env.GROUP_B_ROLE)) return; if (client.user.username == process.env.GROUP_C_LEADER_NAME && !member.roles.has(process.env.GROUP_C_ROLE)) return; - let response = String(dataRequest.SendServerData("getLevelUp", member.user.id)); - let responseArray = response.split(","); - - let responseMessage = responseArray[0]; - let level = Math.floor(parseFloat(responseArray[1])); - let statPoints = parseFloat(responseArray[2]); - - let rankUp = exports.RankUp(client, member, level); - - if (rankUp == "rankUp") { - return [rankUp, level, statPoints]; - } else if (responseMessage === "levelup") { - return ["levelUp", level, statPoints]; - } else { - return ["", level, statPoints]; + let handleResponse = function(response, level, statPoints) { + let rankUp = exports.RankUp(client, member, level); + fn(rankUp === "rankUp" ? rankUp : response, level, statPoints); } + + dataRequest.OnServerData("levelUp", handleResponse, member.user.id); } //GetLevelUp