Skip to content

Commit

Permalink
Do not remove user-data on connection reset
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinSRG committed Aug 24, 2016
1 parent e576c40 commit 94cd59a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/lib/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,15 @@ class Bot {
}
this.nextSend = 0;
this.rooms = {};
this.users = {};
this.status.onDisconnect();
}

clearUserData() {
for (let user in this.users) {
delete this.users[user];
}
}

/* Events */

/**
Expand Down
33 changes: 31 additions & 2 deletions src/server/handlers/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ App.server.setHandler('tools', (context, parts) => {
html += ' | ';
html += '<a class="submenu-option' + (opt in {'seen': 1} ? '-selected' : '') + '" href="/tools/seen/">Seen</a>';
html += ' | ';
html += '<a class="submenu-option' + (opt in {'clearusers': 1} ? '-selected' : '') + '" href="/tools/clearusers/">Clear&nbsp;User-Data</a>';
html += ' | ';
html += '<a class="submenu-option' + (opt in {'hotpatch': 1} ? '-selected' : '') + '" href="/tools/hotpatch/">Hotpatch</a>';
html += ' | ';
html += '<a class="submenu-option' + (opt in {'ddata': 1} ? '-selected' : '') + '" href="/tools/ddata/">Reload Data</a>';
html += '<a class="submenu-option' + (opt in {'ddata': 1} ? '-selected' : '') + '" href="/tools/ddata/">Reload&nbsp;Data</a>';
html += ' | ';
html += '<a class="submenu-option' + (opt in {'cache': 1} ? '-selected' : '') + '" href="/tools/cache/">Clear Cache</a>';
html += '<a class="submenu-option' + (opt in {'cache': 1} ? '-selected' : '') + '" href="/tools/cache/">Clear&nbsp;Cache</a>';
html += ' | ';
html += '<a class="submenu-option' + (opt in {'eval': 1} ? '-selected' : '') + '" href="/tools/eval/">Eval&nbsp;(JavaScript)</a>';
html += '</div>';
Expand All @@ -57,6 +59,9 @@ App.server.setHandler('tools', (context, parts) => {
case 'seen':
toolSeen(context, html, parts);
break;
case 'clearusers':
toolClearUsers(context, html, parts);
break;
case 'hotpatch':
toolHotpatch(context, html, parts);
break;
Expand Down Expand Up @@ -336,6 +341,30 @@ function toolClearCache(context, html, parts) {
context.endWithWebPage(html, {title: "Develoment Tools - Showdown ChatBot"});
}

function toolClearUsers(context, html, parts) {
let ok = null, error = null;
if (context.post.clearusers) {
App.bot.clearUserData();
App.logServerAction(context.user.id, 'Clear User-Data');
ok = "User-Data cleared sucessfully.";
}

html += '<h2>Clear User-Data</h2>';
html += '<p>Clears temporal data stored about pokemon showdown users. ' +
'This includes name, last seen date, last action and alts.</p>';
html += '<form method="post" action="">';
html += '<p><input type="submit" name="clearusers" value="Clear User-Data" /></p>';
html += '</form>';

if (error) {
html += '<p style="padding:5px;"><span class="error-msg">' + error + '</span></p>';
} else if (ok) {
html += '<p style="padding:5px;"><span class="ok-msg">' + ok + '</span></p>';
}

context.endWithWebPage(html, {title: "Develoment Tools - Showdown ChatBot"});
}

/* Auxiliar Functions */

function tryGetRoomTitle(room) {
Expand Down

0 comments on commit 94cd59a

Please sign in to comment.