Skip to content

Commit

Permalink
Fixed remaining issues with 2.0.0
Browse files Browse the repository at this point in the history
Finalized the 2.0.0 version, into 2.0.1.
  • Loading branch information
_FR_Starfox64 committed Oct 2, 2015
1 parent b31e963 commit 80e8742
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
25 changes: 16 additions & 9 deletions addons/foxedbot/lua/foxedbot/sv_foxedbot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FoxedBot.retries = 0
FoxedBot.ready = false

FoxedBot.sock:Create()
FoxedBot.sock:SetOption(0xFFFF, 0x0008, 1)
FoxedBot.sock:SetOption(0xFFFF, 0x0008, 1) -- Enable keepalive

--[[
Sends the ServerKey and ServerID to the bot to authenticate the server.
Expand All @@ -24,7 +24,7 @@ function FoxedBot.auth( sockObj, succ, ip, port )
FoxedBot.sock:Send(packet, true)
FoxedBot.sock:ReceiveUntil("\3") -- Reads until the EndOfText control character.
else
MsgC(Color(200, 25, 25), "[FoxedBot] Connection Failed, retrying in 30 seconds...\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Connection Failed, retrying in 30 seconds...\n")

timer.Simple(30, function()
FoxedBot.sock:Connect(FoxedBot.BotIP, FoxedBot.BotPort)
Expand Down Expand Up @@ -55,10 +55,11 @@ FoxedBot.sock:SetCallbackReceive(function( sockObj, packet )
FoxedBot.ready = false

if (FoxedBot.retries < 2) then
MsgC(Color(200, 25, 25), "[FoxedBot] Connection Denied, retrying...\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Connection Denied, retrying...\n")
FoxedBot.retries = FoxedBot.retries + 1
FoxedBot.auth(nil, true) -- resend the auth data to the bot.
else
MsgC(Color(200, 25, 25), "[FoxedBot] Connection Denied, out of retries, your ServerKey is most likely wrong!\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Connection Denied after 3 attempts, ServerKey or ServerID is most likely wrong!\n")
FoxedBot.sock:Disconnect()
end

Expand All @@ -67,22 +68,26 @@ FoxedBot.sock:SetCallbackReceive(function( sockObj, packet )
elseif FoxedBot.callbacks[callback] then
FoxedBot.callbacks[callback](data)
else
MsgC(Color(200, 25, 25), "[FoxedBot] Attempted to call an unknown callback! ("..callback..")\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Attempted to call an unknown callback! ("..callback..")\n")
end
else
MsgC(Color(200, 25, 25), "[FoxedBot] Received an invalid packet.\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Received an invalid packet.\n")
end
end

FoxedBot.sock:ReceiveUntil("\3")
end)

FoxedBot.sock:SetCallbackDisconnect(function()
MsgC(Color(200, 25, 25), "[FoxedBot] Disconnected!\n")
MsgC(Color(200, 70, 70), "[FoxedBot] Disconnected!\n")

if FoxedBot.ready then
FoxedBot.ready = false
FoxedBot.sock:Disconnect()
FoxedBot.sock:Connect(FoxedBot.BotIP, FoxedBot.BotPort)

timer.Simple(5, function()
FoxedBot.sock:Connect(FoxedBot.BotIP, FoxedBot.BotPort)
end)
end
end)

Expand Down Expand Up @@ -191,5 +196,7 @@ concommand.Add("foxedbot_reload", function ( ply )
end)

hook.Add("ShutDown", "FoxedBot_Disconnect", function()
FoxedBot.sock:Disconnect()
if FoxedBot.sock:GetState() == 7 then
FoxedBot.sock:Disconnect()
end
end)
18 changes: 11 additions & 7 deletions foxedbot.js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,23 @@ app.server.on("connection", function (sock) {
try {
var data = JSON.parse(packet.toString());
} catch (e) {
app.logger.warn(sock.remoteAddress + " send an invalid JSON packet!");
app.logger.warn(sock.remoteAddress + " sent an invalid JSON packet!");
return;
}

if (isNaN(sock.serverID)) {
if (isNaN(sock.serverID)) { // Checks if the socket is authenticated
if (data[1] === "AUTH") {
if (data[2] === Config.serverKey) {
sock.serverID = data[3];
app.Socks[sock.serverID] = sock;
app.logger.info("Server " + sock.serverID + " has been authenticated!");
func.sendToSocket(sock, JSON.stringify(["SYS", "AUTHED"]));
if (Config.servers[data[3]]) { // Checks if the provided serverID exists
sock.serverID = data[3];
app.Socks[sock.serverID] = sock;
app.logger.info("Server " + sock.serverID + " has been authenticated!");
func.sendToSocket(sock, JSON.stringify(["SYS", "AUTHED"]));

return;
return;
} else {
app.logger.warn(sock.remoteAddress + " provided an invalid ServerID!");
}
} else {
app.logger.warn(sock.remoteAddress + " provided the wrong ServerKey!");
}
Expand Down
1 change: 0 additions & 1 deletion foxedbot.js/lib/functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var fs = require("fs");
var net = require("net");
var Config = require("../config/settings.js");
var app = require("../app.js");

Expand Down
5 changes: 1 addition & 4 deletions foxedbot.js/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"name": "foxedbot",
"version": "2.0.0",
"version": "2.0.1",
"description": "A SteamBot for Garry's Mod.",
"main": "./app.js",
"scripts": {
"start": "node app.js"
},
"repository": {
"type": "git",
"url": "https://github.com/Starfox64/FoxedBot"
Expand Down

0 comments on commit 80e8742

Please sign in to comment.