1
0
Fork 0
refactor/models
Matthew 2020-12-18 18:45:58 -05:00
parent abb999f2a5
commit b987a09d21
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
14 changed files with 59 additions and 55 deletions

35
src/class/Context.ts Normal file
View File

@ -0,0 +1,35 @@
import net from 'net';
import { Client } from '.';
export default class Context {
public socket: net.Socket;
public client: Client;
public data: {
username: string,
endpoint: string,
message?: string,
additionalData?: object,
HMAC: string,
}
constructor(socket: net.Socket, data: string, client: Client) {
const parsed: { Username: string, Type: string, Message?: string, Data?: object, HMAC: string } = JSON.parse(data);
this.socket = socket;
this.client = client;
this.data = {
username: parsed.Username,
endpoint: parsed.Type,
message: parsed.Message,
additionalData: parsed.Data,
HMAC: parsed.HMAC,
};
}
public send(v: string) {
this.socket.write(`${v.toString()}\n`);
this.socket.destroy();
}
}

11
src/class/TCPHandler.ts Normal file
View File

@ -0,0 +1,11 @@
import { Context } from '.';
export default class TCPHandler {
public endpoint: string;
constructor(endpoint?: string) {
this.endpoint = endpoint;
}
public handle(ctx: Context): Promise<any> { return Promise.resolve(); }
}

View File

@ -2,6 +2,7 @@ export { default as AccountUtil } from './AccountUtil';
export { default as Client } from './Client'; export { default as Client } from './Client';
export { default as Collection } from './Collection'; export { default as Collection } from './Collection';
export { default as Command } from './Command'; export { default as Command } from './Command';
export { default as Context } from './Context';
export { default as Event } from './Event'; export { default as Event } from './Event';
export { default as LocalStorage } from './LocalStorage'; export { default as LocalStorage } from './LocalStorage';
export { default as Report } from './Report'; export { default as Report } from './Report';
@ -9,4 +10,5 @@ export { default as RichEmbed } from './RichEmbed';
export { default as Route } from './Route'; export { default as Route } from './Route';
export { default as Security } from './Security'; export { default as Security } from './Security';
export { default as Server } from './Server'; export { default as Server } from './Server';
export { default as TCPHandler } from './TCPHandler';
export { default as Util } from './Util'; export { default as Util } from './Util';

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class KillPID extends TCPHandler { export default class KillPID extends TCPHandler {
constructor() { constructor() {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class Lock extends TCPHandler { export default class Lock extends TCPHandler {
constructor() { constructor() {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class ProcessCount extends TCPHandler { export default class ProcessCount extends TCPHandler {
constructor() { constructor() {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
import { dataConversion } from '../../functions'; import { dataConversion } from '../../functions';
export default class RAM extends TCPHandler { export default class RAM extends TCPHandler {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class RAMLimits extends TCPHandler { export default class RAMLimits extends TCPHandler {
constructor() { constructor() {

View File

@ -1,5 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context, Report } from '../../class';
import { Report } from '../../class';
export default class Score extends TCPHandler { export default class Score extends TCPHandler {
constructor() { constructor() {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class SSHLogins extends TCPHandler { export default class SSHLogins extends TCPHandler {
constructor() { constructor() {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
import { dataConversion } from '../../functions'; import { dataConversion } from '../../functions';
export default class Storage extends TCPHandler { export default class Storage extends TCPHandler {

View File

@ -1,4 +1,4 @@
import { TCPHandler, Context } from '..'; import { TCPHandler, Context } from '../../class';
export default class UserInfo extends TCPHandler { export default class UserInfo extends TCPHandler {
constructor() { constructor() {

View File

@ -1 +1 @@
export { default as CSCLI, TCPHandler, Context } from './main'; export { default as CSCLI } from './main';

View File

@ -4,53 +4,10 @@
import net from 'net'; import net from 'net';
import crypto from 'crypto'; import crypto from 'crypto';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import { Client, Collection } from '../class'; import { Client, Collection, Context, TCPHandler } from '../class';
import * as handlerFiles from './handlers'; import * as handlerFiles from './handlers';
export class TCPHandler {
public endpoint: string;
constructor(endpoint?: string) {
this.endpoint = endpoint;
}
public handle(ctx: Context): Promise<any> { return Promise.resolve(); }
}
export class Context {
public socket: net.Socket;
public client: Client;
public data: {
username: string,
endpoint: string,
message?: string,
additionalData?: object,
HMAC: string,
}
constructor(socket: net.Socket, data: string, client: Client) {
const parsed: { Username: string, Type: string, Message?: string, Data?: object, HMAC: string } = JSON.parse(data);
this.socket = socket;
this.client = client;
this.data = {
username: parsed.Username,
endpoint: parsed.Type,
message: parsed.Message,
additionalData: parsed.Data,
HMAC: parsed.HMAC,
};
}
public send(v: string) {
this.socket.write(`${v.toString()}\n`);
this.socket.destroy();
}
}
export default class CSCLI { export default class CSCLI {
public client: Client; public client: Client;