Skip to content

Commit

Permalink
feat: sge service
Browse files Browse the repository at this point in the history
  • Loading branch information
KatoakDR committed Nov 15, 2023
1 parent 4275d68 commit 958abb0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 2 additions & 0 deletions electron/main/sge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './sge.types';
export * from './sge.service';
8 changes: 4 additions & 4 deletions electron/main/sge/sge.login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createSelfSignedCertConnectOptions,
downloadCertificate,
sendAndReceive,
} from '../tls/tls.utils';
} from '../tls';
import type {
SGECharacter,
SGEGame,
Expand All @@ -32,7 +32,7 @@ let cachedTlsCertificate: tls.PeerCertificate | undefined;
* https://elanthipedia.play.net/SGE_protocol_(saved_post)
* https://github.com/WarlockFE/warlock2/wiki/EAccess-Protocol
*/
export async function login(options: {
export async function loginCharacter(options: {
/**
* Play.net account name
*/
Expand Down Expand Up @@ -171,9 +171,9 @@ async function connect(
})
);

logger.info('connecting to login server');
logger.info('connecting to login server', { host, port });
const socket = tls.connect(mergedOptions, (): void => {
logger.info('connected to login server');
logger.info('connected to login server', { host, port });
});

socket.on('end', (): void => {
Expand Down
43 changes: 43 additions & 0 deletions electron/main/sge/sge.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { listCharacters, loginCharacter } from './sge.login';
import type {
SGECharacter,
SGEGameCode,
SGEGameCredentials,
SGEService,
} from './sge.types';

export class SGEServiceImpl implements SGEService {
private username: string;
private password: string;
private gameCode: SGEGameCode;

constructor(options: {
username: string;
password: string;
gameCode: SGEGameCode;
}) {
this.username = options.username;
this.password = options.password;
this.gameCode = options.gameCode;
}

public async loginCharacter(
characterName: string
): Promise<SGEGameCredentials> {
const response = await loginCharacter({
username: this.username,
password: this.password,
gameCode: this.gameCode,
characterName,
});
return response.credentials;
}

public async listCharacters(): Promise<Array<SGECharacter>> {
return listCharacters({
username: this.username,
password: this.password,
gameCode: this.gameCode,
});
}
}
5 changes: 5 additions & 0 deletions electron/main/sge/sge.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ export interface SGECharacter {
*/
name: string;
}

export interface SGEService {
loginCharacter(characterName: string): Promise<SGEGameCredentials>;
listCharacters(): Promise<Array<SGECharacter>>;
}

0 comments on commit 958abb0

Please sign in to comment.