mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-29 02:24:27 +11:00
Created an empty shell of a server
This commit is contained in:
1
.envdev
1
.envdev
@@ -82,3 +82,4 @@ RANK_3_THRESHOLD=30
|
|||||||
# Server
|
# Server
|
||||||
SERVER_ADDRESS="http://127.0.0.1"
|
SERVER_ADDRESS="http://127.0.0.1"
|
||||||
SERVER_PASS_KEY=""
|
SERVER_PASS_KEY=""
|
||||||
|
SERVER_PORT="4500"
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ client.on('ready', async () => {
|
|||||||
console.log("Logged in as: " + client.user.username + " - " + client.user.id);
|
console.log("Logged in as: " + client.user.username + " - " + client.user.id);
|
||||||
|
|
||||||
//ADAM updates stamina (1) and health by 1% every 2 min.
|
//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.');
|
console.log('Updating STAMINA every 2 min.');
|
||||||
shared.SendServerData("updateStamina");
|
shared.SendServerData("updateStamina");
|
||||||
});
|
});
|
||||||
|
|||||||
198
ADAM/core.js
198
ADAM/core.js
@@ -3,7 +3,6 @@ exports = module.exports = {};
|
|||||||
let dataRequest = require("../Shared/data_request");
|
let dataRequest = require("../Shared/data_request");
|
||||||
let discord = require('discord.js');
|
let discord = require('discord.js');
|
||||||
let shared = require("../Shared/shared");
|
let shared = require("../Shared/shared");
|
||||||
let calcRandom = require('../Shared/calc_random');
|
|
||||||
|
|
||||||
//ProcessGameplayCommands
|
//ProcessGameplayCommands
|
||||||
//client - discord.js client
|
//client - discord.js client
|
||||||
@@ -17,66 +16,15 @@ exports.ProcessGameplayCommands = function(client, message, dialog) {
|
|||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "checkin":
|
case "checkin":
|
||||||
let checkinAmount = calcRandom.Random(4, 9);
|
exports.ProcessCheckinCommand(client, message.member, message.channel, dialog);
|
||||||
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));
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case "give": //TODO: fold this code into a function
|
case "give":
|
||||||
let amount = Math.floor(parseFloat(args[0]));
|
exports.ProcessGiveCommand(client, message, args, dialog);
|
||||||
|
|
||||||
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));
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case "stats":
|
case "stats":
|
||||||
exports.ProcessStatsCommand(client, message.member, message.channel, dialog);
|
exports.ProcessStatsCommand(client, message.member, message.channel, dialog);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,16 +40,15 @@ exports.ProcessGameplayCommands = function(client, message, dialog) {
|
|||||||
//factionShorthand - the shorthand name of the new faction (TEMPORARY)
|
//factionShorthand - the shorthand name of the new faction (TEMPORARY)
|
||||||
exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dialog, factionShorthand) {
|
exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dialog, factionShorthand) {
|
||||||
//tailor this for each faction leader?
|
//tailor this for each faction leader?
|
||||||
shared.ChangeFaction(client, factionRole, message.channel, message.member)
|
let handleResponse = async function(response) {
|
||||||
.then(result => {
|
switch (response) {
|
||||||
switch (result) {
|
|
||||||
case "alreadyJoined":
|
case "alreadyJoined":
|
||||||
shared.SendPublicMessage(client, message.channel, dialog("alreadyJoined" + factionShorthand, message.author.id));
|
shared.SendPublicMessage(client, message.channel, dialog("alreadyJoined" + factionShorthand, message.author.id));
|
||||||
break;
|
break;
|
||||||
case "hasConvertedToday":
|
case "conversionLocked":
|
||||||
shared.SendPublicMessage(client, message.channel, dialog("conversionLocked", message.author.id));
|
shared.SendPublicMessage(client, message.channel, dialog("conversionLocked", message.author.id));
|
||||||
break;
|
break;
|
||||||
case "createdUser":
|
case "newUser":
|
||||||
shared.SendPublicMessage(client, message.author, shared.GetFactionChannel(factionRole), dialog("newUserPublicMessage", shared.GetFactionName(factionRole), shared.GetFactionChannel(factionRole)));
|
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)));
|
shared.SendPrivateMessage(client, message.author, dialog("newUserPrivateMessage", dialog("newUserPrivateMessageRemark" + factionShorthand)));
|
||||||
break;
|
break;
|
||||||
@@ -112,9 +59,83 @@ exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dia
|
|||||||
//DEBUGGING
|
//DEBUGGING
|
||||||
console.log("processFactionChangeAttempt failed:" + result);
|
console.log("processFactionChangeAttempt failed:" + result);
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch(console.error);
|
|
||||||
return true;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataRequest.OnServerData("transfer", handleResponse, message.author.id, targetMember.id, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataRequest.OnServerData("account", handleResponse, message.author.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ProcessStatsCommand
|
//ProcessStatsCommand
|
||||||
@@ -124,49 +145,21 @@ exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dia
|
|||||||
//dialog - dialog function
|
//dialog - dialog function
|
||||||
exports.ProcessStatsCommand = function(client, member, channel, dialog) {
|
exports.ProcessStatsCommand = function(client, member, channel, dialog) {
|
||||||
exports.HandleLevelUp(client, member, channel, dialog);
|
exports.HandleLevelUp(client, member, channel, dialog);
|
||||||
let stats = exports.GetStats(member.user);
|
exports.GetStats(member.user, (stats) => {
|
||||||
exports.PrintStats(client, member, channel, stats);
|
exports.PrintStats(client, member, channel, stats);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetStats
|
//GetStats
|
||||||
//user - discord.js user OR username
|
//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
|
//handle user strings
|
||||||
if (typeof(user) === "string") {
|
if (typeof(user) === "string") {
|
||||||
user = client.users.find(item => item.username === user || item.id === user);
|
user = client.users.find(item => item.username === user || item.id === user);
|
||||||
}
|
}
|
||||||
|
|
||||||
let userStatsResponse = String(dataRequest.LoadServerData("userStats", user.id)).split(",");
|
dataRequest.OnServerData("userStats", fn, user.id);
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//PrintStats
|
//PrintStats
|
||||||
@@ -229,19 +222,16 @@ exports.HandleLevelUp = function(client, member, channel, dialog) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sees if the user is supposed to level up
|
// Sees if the user is supposed to level up
|
||||||
let [levelUpResponse, level, statPoints] = shared.LevelUp(client, member);
|
let handleResponse = function(response, level, statPoints) {
|
||||||
|
|
||||||
//handle channel strings
|
|
||||||
if (typeof(channel) === "string") {
|
|
||||||
channel = client.channels.find(item => item.name === channel || item.id === channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
//handle levelling up
|
//handle levelling up
|
||||||
if (levelUpResponse === "levelUp" || levelUpResponse === "RankUp") {
|
if (response === "levelUp" || response === "RankUp") {
|
||||||
if (level >= process.env.RANK_3_THRESHOLD) {
|
if (level >= process.env.RANK_3_THRESHOLD) {
|
||||||
shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), level));
|
shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), level));
|
||||||
} else {
|
} else {
|
||||||
shared.SendPublicMessage(client, member.user, channel, dialog("LevelUp", dialog("levelUpRemark"), level, statPoints));
|
shared.SendPublicMessage(client, member.user, channel, dialog("LevelUp", dialog("levelUpRemark"), level, statPoints));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shared.LevelUp(client, member, handleResponse);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodejs-elasticbeanstalk",
|
"name": "ADAM",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ function processBasicCommands(client, message) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case "genesis":
|
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
|
//ADAM and the faction leaders print the intros in the gate
|
||||||
case "introgenesis":
|
case "introgenesis":
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodejs-elasticbeanstalk",
|
"name": "ADAM_CptMon",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ function processBasicCommands(client, message) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case "hand":
|
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
|
//ADAM and the faction leaders print the intros in the gate
|
||||||
case "introhand":
|
case "introhand":
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodejs-elasticbeanstalk",
|
"name": "ADAM_Dairo",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ function processBasicCommands(client, message) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case "obsidian":
|
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
|
//ADAM and the faction leaders print the intros in the gate
|
||||||
case "introobsidian":
|
case "introobsidian":
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodejs-elasticbeanstalk",
|
"name": "ADAM_Kamala",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "nodejs-elasticbeanstalk",
|
"name": "Librarian",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
|
|||||||
@@ -1,3 +1,114 @@
|
|||||||
// .env Variables
|
// .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"]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
20
SERVER_City/package.json
Normal file
20
SERVER_City/package.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,16 +2,22 @@
|
|||||||
exports = module.exports = {};
|
exports = module.exports = {};
|
||||||
|
|
||||||
require("dotenv").config({path: "../.env"});
|
require("dotenv").config({path: "../.env"});
|
||||||
let request = require("sync-request");
|
|
||||||
|
|
||||||
exports.LoadServerData = function(dataType, usersID = "") {
|
//socket tools
|
||||||
let response = request("GET", `${process.env.SERVER_ADDRESS}/getData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}`);
|
let io = require("socket.io-client")(`${process.env.SERVER_ADDRESS}:${process.env.SERVER_PORT}`);
|
||||||
// console.log(response.getBody());
|
|
||||||
return response.getBody();
|
//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 = ""){
|
//OnServerData
|
||||||
let response = request("GET", `${process.env.SERVER_ADDRESS}/sendData.php?pk=${process.env.SERVER_PASS_KEY}&dataType=${dataType}&userid=${usersID}&dataToSend=${dataToSend}&dataToSend2=${dataToSend2}`);
|
//dataType - the type of data being sent and received
|
||||||
// console.log(response.getBody());
|
//fn (optional) - the aknowledgement function that is called on the other end (takes the result as an argument)
|
||||||
return response.getBody();
|
//...data (optional) - any data you wish to send
|
||||||
|
exports.OnServerData = function(dataType, fn, ...data) {
|
||||||
|
io.emit(dataType, { data: data }, fn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ exports.GetFactionChannel = function(factionRole) {
|
|||||||
//factionRole - a faction role
|
//factionRole - a faction role
|
||||||
//channel - discord.js channel OR channel name
|
//channel - discord.js channel OR channel name
|
||||||
//member - discord.js member
|
//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
|
//factionRole must be a faction role
|
||||||
if (!exports.CheckFaction(factionRole)) {
|
if (!exports.CheckFaction(factionRole)) {
|
||||||
throw "factionRole is not a faction!";
|
throw "factionRole is not a faction!";
|
||||||
@@ -79,31 +79,23 @@ exports.ChangeFaction = async function(client, factionRole, channel, member) {
|
|||||||
|
|
||||||
if (member.roles.has(factionRole)) {
|
if (member.roles.has(factionRole)) {
|
||||||
//can't change to this faction
|
//can't change to this faction
|
||||||
return "alreadyJoined";
|
fn("alreadyJoined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataRequest.LoadServerData("hasConvertedToday", member.user.id) == 1) {
|
let handleResponse = async function(response) {
|
||||||
//can't change too fast
|
if (response === "conversionLocked") { //can't change too fast
|
||||||
return "hasConvertedToday";
|
fn(response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Creates a new user
|
|
||||||
var newUserResponse = String(dataRequest.SendServerData("newUser", member.user.id, "New user."));
|
|
||||||
|
|
||||||
//joins the new faction
|
//joins the new faction
|
||||||
await member.removeRole(process.env.GROUP_A_ROLE);
|
await member.removeRole(process.env.GROUP_A_ROLE);
|
||||||
await member.removeRole(process.env.GROUP_B_ROLE);
|
await member.removeRole(process.env.GROUP_B_ROLE);
|
||||||
await member.removeRole(process.env.GROUP_C_ROLE);
|
await member.removeRole(process.env.GROUP_C_ROLE);
|
||||||
await member.addRole(factionRole);
|
await member.addRole(factionRole);
|
||||||
|
|
||||||
//send the server the info (for logging)
|
fn(response);
|
||||||
dataRequest.SendServerData("conversion", member.user.id, "Converted to " + exports.GetFactionName(factionRole));
|
};
|
||||||
|
|
||||||
if (newUserResponse === "createdUser") {
|
dataRequest.OnServerData("conversion", handleResponse, member.user.id);
|
||||||
//send the private welcoming message
|
|
||||||
return newUserResponse;
|
|
||||||
} else {
|
|
||||||
//send the public welcoming message
|
|
||||||
return "joined";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "shared",
|
"name": "Shared",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "calc_random.js",
|
"main": "shared.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
@@ -10,6 +10,6 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^6.1.0",
|
"dotenv": "^6.1.0",
|
||||||
"sync-request": "^6.0.0"
|
"socket.io-client": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ exports.AddXP = function(client, user, amount) {
|
|||||||
//LevelUp
|
//LevelUp
|
||||||
//client - discord.js client
|
//client - discord.js client
|
||||||
//member - member to get the level up
|
//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
|
//handle member strings
|
||||||
if (typeof(member) === "string") {
|
if (typeof(member) === "string") {
|
||||||
//get the member
|
//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_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;
|
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 handleResponse = function(response, level, statPoints) {
|
||||||
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);
|
let rankUp = exports.RankUp(client, member, level);
|
||||||
|
fn(rankUp === "rankUp" ? rankUp : response, level, statPoints);
|
||||||
if (rankUp == "rankUp") {
|
|
||||||
return [rankUp, level, statPoints];
|
|
||||||
} else if (responseMessage === "levelup") {
|
|
||||||
return ["levelUp", level, statPoints];
|
|
||||||
} else {
|
|
||||||
return ["", level, statPoints];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataRequest.OnServerData("levelUp", handleResponse, member.user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetLevelUp
|
//GetLevelUp
|
||||||
|
|||||||
Reference in New Issue
Block a user