Skip to content

Commit

Permalink
Getting an error on lobby creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLlamoPablo committed Jan 12, 2017
1 parent 100c4df commit e864b89
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/commands/admin/force-lobby-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = new Clapp.Command({
fulfill("Error: the specified event `" + argv.args.event + "` doesn't exist.");
} else {
db.events.getLobbyBotId(event)
// Here, "closing" actually means "starting".
// Here, "closing" actually means "starting". TODO NOT TRUE LUL
.then(botID => context.dotaHandler.closeLobby(botID, true))
.then(() => fulfill(`Forced lobby start for the event ${event.id}.`))
.catch(err => {
Expand Down
39 changes: 0 additions & 39 deletions lib/modules/dbhandler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,45 +577,6 @@ const config = {
}).catch(reject);
});
}
},

steam: { // TODO remove this
getCredentials: function() {
return new Promise((fulfill, reject) => {
db("config").select(["steam_username", "steam_password", "steam_guard_code"])
.then(rows => {
fulfill({
username: rows[0].steam_username,
password: rows[0].steam_password,
auth_code: rows[0].steam_guard_code || null
});
}).catch(reject);
});
},

getSentryFile: function() {
return new Promise((fulfill, reject) => {
db("config").select("steam_sentry_file").then(rows => {
fulfill(rows[0] ? rows[0].steam_sentry_file : null);
}).catch(reject);
});
},

saveSentryFile: function(sentryFile) {
return new Promise((fulfill, reject) => {
db("config").update({
steam_sentry_file: sentryFile
}).then(fulfill).catch(reject);
});
},

deleteAuthCode: function() {
return new Promise((fulfill, reject) => {
db("config").update({
steam_guard_code: null
}).then(fulfill).catch(reject);
});
}
}

};
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/dbhandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ module.exports = {
addInstant: core.events.addInstant,
addInhouse: core.events.addInhouse,
updateWaiting: core.events.updateWaiting,
updateLobbyEnded: core.events.updateLobbyStatus,
updateLobbyStatus: core.events.updateLobbyStatus,
updateLobbyBotId: core.events.updateLobbyBotId,
deleteEvent: core.events.deleteEvent
},

Expand Down
11 changes: 6 additions & 5 deletions lib/modules/dotahandler/DotaClientX.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class DotaClientX extends Dota2.Dota2Client {

createLobby(inhouseProps) {
return new Promise((fulfill, reject) => {
this.client.leavePracticeLobby();

this.currentLobby.event = inhouseProps.event;
this.currentLobby.name = inhouseProps.event.name;
this.currentLobby.password = DotaClientX.generatePassword();
Expand Down Expand Up @@ -170,7 +168,7 @@ class DotaClientX extends Dota2.Dota2Client {
}

this.createPracticeLobby(
this.currentLobb.password,
this.currentLobby.password,
options,
err => {
if (!err) {
Expand All @@ -186,7 +184,10 @@ class DotaClientX extends Dota2.Dota2Client {
this.inviteAll().catch(reject);
fulfill();
} else {
reject(new Error("[DOTA] Error creating lobby - Error code: " + err));
// TODO this is giving error 2 on lobby creation
reject(new Error("[DOTA] Error creating lobby - Error code: " + err
+ "\nList of error codes: https://github.com/Arcana/node-dota2/blob/86f02" +
"0e01dba86af3ec02323a8325243b8d9d0c2/handlers/helper.js#L5"));
}
}
);
Expand Down Expand Up @@ -324,7 +325,7 @@ class DotaClientX extends Dota2.Dota2Client {
/**
* @returns {boolean} Whether or not the client is currently in a lobby.
*/
inLoby() {
inLobby() {
return !!this.currentLobby.name;
}

Expand Down
14 changes: 8 additions & 6 deletions lib/modules/dotahandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DotaHandler { // TODO !!!! make sure that all commands use the correct api
let client = this._getDotaClientById(botID);

if (client !== null) {
if (client.inLoby()) {
if (client.inLobby()) {
client.closeLobby(force).then(fulfill).catch(reject);
} else {
let err = new Error();
Expand All @@ -90,7 +90,7 @@ class DotaHandler { // TODO !!!! make sure that all commands use the correct api
let client = this._getDotaClientById(botID);

if (client !== null) {
if (client.inLoby()) {
if (client.inLobby()) {
client.invite(discordID).then(fulfill).catch(reject);
} else {
reject(new Error(`The bot with ID ${botID} is not in a lobby.`));
Expand All @@ -113,7 +113,7 @@ class DotaHandler { // TODO !!!! make sure that all commands use the correct api
let client = this._getDotaClientById(botID);

if (client !== null) {
if (client.inLoby()) {
if (client.inLobby()) {
return {
name: client.currentLobby.name,
password: client.currentLobby.name
Expand All @@ -131,11 +131,13 @@ class DotaHandler { // TODO !!!! make sure that all commands use the correct api
* @private
*/
_getAvailableDotaClient() {
this.bots.forEach(bot => {
if (!bot.dota.client.inLoby()) {
for (let i = 0; i < this.bots.length; i++) {
let bot = this.bots[i];

if (!bot.dota.client.inLobby()) {
return bot.dota.client;
}
});
}

return null;
}
Expand Down
31 changes: 30 additions & 1 deletion lib/modules/steambotshandler/SteamBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,27 @@ class SteamBot {
callback({ sha_file: hashedSentry });
});

this.steam.client.on("error", console.error);
this.steam.client.on("error", err => {
if (err.message === "Disconnected") {
this._logErr("Unexpected Steam disconnection.\n\n" +

"The cause of this issue is unknown. All I know is that this is not the\n" +
"fault of ScheduleBot, but rather, of node-steam.\n" +
"If you have multiple Steam bots, try disabling this one. If this is the\n" +
"only one, try disabling Steam Guard. I know, it's not the ideal solution,\n" +
"but I don't think there's anything else I can do.\n\n" +

"Open an issue on GitHub if you'd like to discuss this further.\n\n" +

"Debug info:\n");

console.error(err);
process.exit(1);
} else {
this._logErr("Unexpected error:");
console.error(err);
}
});
}

/**
Expand Down Expand Up @@ -149,6 +169,15 @@ class SteamBot {
console.log(this.prefix.replace("SECTION", logSection) + " " + msg);
}

/**
* @param {string} msg
* @param {string} [logSection="STEAM"]
* @private
*/
_logErr(msg, logSection = "STEAM") {
console.error(this.prefix.replace("SECTION", logSection) + " Error: " + msg);
}

}

module.exports = SteamBot;
2 changes: 1 addition & 1 deletion lib/modules/steambotshandler/loadbot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const SteamBot = require("SteamBot");
const SteamBot = require("./SteamBot");

/**
* @typedef {object} BotObject
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/summaryhandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const ELobbyStatus = require("../../structures/enums/ELobbyStatus");

"use strict";

/**
* @class SummaryHandler
* @property {Discord.Client} bot
* @property {Discord.Channel} masterChannel
*/
class SummaryHandler {

/**
Expand Down Expand Up @@ -168,7 +173,7 @@ class SummaryHandler {
summary += "The lobby for this event is closed.";
break;
case ELobbyStatus.NO_AVAILABLE_BOT:
summary += "All Steam bots are currently full. Please wait " +
summary += "All Steam bots are currently busy. Please wait " +
"until one becomes free, or talk to an admin.";
break;
}
Expand Down
34 changes: 32 additions & 2 deletions scripts/setup-steam.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,38 @@ function removeBot(id, client) {

if (!err){

console.log("\nThis bot has been successfully removed from the database.");
process.exit();
client.query("SELECT * FROM steam_bots", (err, result) => {

if (err) {
console.error(err);
process.exit(1);
}

// If there are no more bots, restart the sequences, so the next bot
// is assigned ID 1.
if (result.rows.length === 0) {
client.query("TRUNCATE TABLE public.steam_bots" +
" RESTART IDENTITY RESTRICT;", err => {

if (err) {
console.error(err);
process.exit(1);
}

console.log("\nThis bot has been successfully removed from the" +
"database.");
process.exit();

});
} else {
console.log("\nThis bot has been successfully removed from the" +
"database.");
process.exit();
}

});



}else {
console.error(err);
Expand Down

0 comments on commit e864b89

Please sign in to comment.