Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/authserver/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AUTH_DB_CONNECTION_URL="sqlite://authserver.db"
LOG_LEVEL="debug"
69 changes: 69 additions & 0 deletions app/authserver/AuthServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { IncomingMessage, ServerResponse, createServer } from "http";
import { getServerLogger } from "rusty-motors-shared";
import { AuthServerConfig } from "./config.ts";
import { handleAuthLogin } from "./handleAuthLogin.ts";
import { handleShardList } from "./handleShardList.ts";

export class AuthServer {

constructor(private config: AuthServerConfig, private log: ReturnType<typeof getServerLogger>) {
this.log = log.child({ name: "auth-server" });
this.config = config;
}

handleRequest(req: IncomingMessage, res: ServerResponse) {
if (!req.url || !req.method) {
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end('Bad Request\n');
return;
}

// Handle incoming requests here
this.log.info(`Received request: ${req.method} ${new URL(req.url, `http://${req.headers.host}`).pathname}`);

if (req.url.startsWith("/AuthLogin")) {
// Handle AuthLogin request
handleAuthLogin.call(this, req, res);
} else if (req.url === "/ShardList/") {
// Handle ShardList request
// Implement shard list retrieval logic here
handleShardList.call(this, req, res);
}
else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not Found\n');
return;
}
}

public start() {
this.log.info("AuthServer started successfully.");
// Initialize server components here (e.g., HTTP server, routes, etc.)
const server = createServer((this.handleRequest).bind(this));

const port = parseInt("3000", 10);
server.listen(port, '0.0.0.0', () => {
this.log.info(`AuthServer listening on port ${port}`);
});

process.on('SIGINT', () => {
this.log.info('Received SIGINT. Shutting down gracefully...');
server.close(() => {
this.stop();
process.exit(0);
});
});

process.on('SIGTERM', () => {
this.log.info('Received SIGTERM. Shutting down gracefully...');
server.close(() => {
this.stop();
process.exit(0);
});
});
}
public stop() {
this.log.info("AuthServer stopped successfully.");
// Clean up resources here
}
}
27 changes: 27 additions & 0 deletions app/authserver/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// detroit is a game server, written from scratch, for an old game
// Copyright (C) <2017> <Drazi Crendraven>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

export interface AuthServerConfig {
dbConnectionUrl: string;
logLevel: string;
}

export function getConfig() : AuthServerConfig {
return {
dbConnectionUrl: process.env.AUTH_DB_CONNECTION_URL || "sqlite://:memory:",
logLevel: process.env.LOG_LEVEL || "debug",
};
Comment on lines +17 to +26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing port configuration: The AuthServer tries to read a 'port' property from the config but it's not defined in the AuthServerConfig interface or getConfig function. This will cause the server to always use the default port 3000.

Suggested change
export interface AuthServerConfig {
dbConnectionUrl: string;
logLevel: string;
}
export function getConfig() : AuthServerConfig {
return {
dbConnectionUrl: process.env.AUTH_DB_CONNECTION_URL || "sqlite://:memory:",
logLevel: process.env.LOG_LEVEL || "debug",
};
export interface AuthServerConfig {
dbConnectionUrl: string;
logLevel: string;
port: string;
}
export function getConfig() : AuthServerConfig {
return {
dbConnectionUrl: process.env.AUTH_DB_CONNECTION_URL || "sqlite://:memory:",
logLevel: process.env.LOG_LEVEL || "debug",
port: process.env.PORT || "3000",
};
}

Did we get this right? 👍 / 👎 to inform future reviews.

}
26 changes: 26 additions & 0 deletions app/authserver/databaseConstrants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Constants
export const DATABASE_PATH = process.env["DATABASE_PATH"] ?? "data/lotus.db";
// SQL Queries
export const SQL = {
CREATE_USER_TABLE: `
CREATE TABLE IF NOT EXISTS user(
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
customerId INTEGER PRIMARY KEY NOT NULL
) STRICT`,
CREATE_SESSION_TABLE: `
CREATE TABLE IF NOT EXISTS session(
id INTEGER PRIMARY KEY AUTOINCREMENT,
contextId TEXT UNIQUE NOT NULL,
customerId INTEGER NOT NULL,
profileId INTEGER DEFAULT 0

) STRICT`,
INSERT_USER:
"INSERT INTO user (username, password, customerId) VALUES (?, ?, ?)",
FIND_USER: "SELECT * FROM user WHERE username = ? AND password = ?",
GET_ALL_USERS: "SELECT * FROM user",
UPDATE_SESSION:
"INSERT OR REPLACE INTO session (contextId, customerId, profileId) VALUES (?, ?, ?)",
FIND_SESSION_BY_CONTEXT: "SELECT * FROM session WHERE contextId = ?",
} as const;
Loading
Loading