Skip to content

Commit 958abb0

Browse files
committed
feat: sge service
1 parent 4275d68 commit 958abb0

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

electron/main/sge/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './sge.types';
2+
export * from './sge.service';

electron/main/sge/sge.login.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createSelfSignedCertConnectOptions,
66
downloadCertificate,
77
sendAndReceive,
8-
} from '../tls/tls.utils';
8+
} from '../tls';
99
import type {
1010
SGECharacter,
1111
SGEGame,
@@ -32,7 +32,7 @@ let cachedTlsCertificate: tls.PeerCertificate | undefined;
3232
* https://elanthipedia.play.net/SGE_protocol_(saved_post)
3333
* https://github.com/WarlockFE/warlock2/wiki/EAccess-Protocol
3434
*/
35-
export async function login(options: {
35+
export async function loginCharacter(options: {
3636
/**
3737
* Play.net account name
3838
*/
@@ -171,9 +171,9 @@ async function connect(
171171
})
172172
);
173173

174-
logger.info('connecting to login server');
174+
logger.info('connecting to login server', { host, port });
175175
const socket = tls.connect(mergedOptions, (): void => {
176-
logger.info('connected to login server');
176+
logger.info('connected to login server', { host, port });
177177
});
178178

179179
socket.on('end', (): void => {

electron/main/sge/sge.service.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { listCharacters, loginCharacter } from './sge.login';
2+
import type {
3+
SGECharacter,
4+
SGEGameCode,
5+
SGEGameCredentials,
6+
SGEService,
7+
} from './sge.types';
8+
9+
export class SGEServiceImpl implements SGEService {
10+
private username: string;
11+
private password: string;
12+
private gameCode: SGEGameCode;
13+
14+
constructor(options: {
15+
username: string;
16+
password: string;
17+
gameCode: SGEGameCode;
18+
}) {
19+
this.username = options.username;
20+
this.password = options.password;
21+
this.gameCode = options.gameCode;
22+
}
23+
24+
public async loginCharacter(
25+
characterName: string
26+
): Promise<SGEGameCredentials> {
27+
const response = await loginCharacter({
28+
username: this.username,
29+
password: this.password,
30+
gameCode: this.gameCode,
31+
characterName,
32+
});
33+
return response.credentials;
34+
}
35+
36+
public async listCharacters(): Promise<Array<SGECharacter>> {
37+
return listCharacters({
38+
username: this.username,
39+
password: this.password,
40+
gameCode: this.gameCode,
41+
});
42+
}
43+
}

electron/main/sge/sge.types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ export interface SGECharacter {
7373
*/
7474
name: string;
7575
}
76+
77+
export interface SGEService {
78+
loginCharacter(characterName: string): Promise<SGEGameCredentials>;
79+
listCharacters(): Promise<Array<SGECharacter>>;
80+
}

0 commit comments

Comments
 (0)