💵 Finish ExchangeHub

Fixes #16
This commit is contained in:
Brendan Lane 2020-12-22 00:29:13 -05:00
parent 41cf5f6f2e
commit 312f769d95
9 changed files with 155 additions and 24 deletions

View File

@ -15,7 +15,7 @@ These are all the versions that we support right now.
## Reporting a Vulnerability ## Reporting a Vulnerability
You can [email](mailto:me@brndnln.dev?cc=bluebeargreen2@gmail.com&subject=%F0%9F%90%9B%20Security%20Issue%20in%20vexico%2Fspookvooper-api&body=This%20is%20a%20security%20issue%20email.%0D%0A%0D%0APlease%20describe%20the%20issue%20and%20include%3A%0D%0A-%20Screenshots%0D%0A-%20Code%20Snippets%0D%0A-%20Examples%20of%20how%20an%20enterprising%20individual%20could%20use%20this%20to%20their%20advantage%0D%0A-%20Pictures%20of%20cats%20(they%20are%20always%20fun)%0D%0A%0D%0AThank%20you%20for%20showing%20enough%20interest%20in%20our%20software%2C%20and%20more%20importantly%2C%20thank%20you%20for%20breaking%20it.%0D%0AHappy%20Hacking!%0D%0A-%20Brendan) You can [email](mailto:me@brndnln.dev?cc=brycebauer@bluebeargreen.live&subject=%F0%9F%90%9B%20Security%20Issue%20in%20vexico%2Fspookvooper-api&body=This%20is%20a%20security%20issue%20email.%0D%0A%0D%0APlease%20describe%20the%20issue%20and%20include%3A%0D%0A-%20Screenshots%0D%0A-%20Code%20Snippets%0D%0A-%20Examples%20of%20how%20an%20enterprising%20individual%20could%20use%20this%20to%20their%20advantage%0D%0A-%20Pictures%20of%20cats%20(they%20are%20always%20fun)%0D%0A%0D%0AThank%20you%20for%20showing%20enough%20interest%20in%20our%20software%2C%20and%20more%20importantly%2C%20thank%20you%20for%20breaking%20it.%0D%0AHappy%20Hacking!%0D%0A-%20Brendan)
us about your findings, just don't send them to us over Discord, post them in any public places, etc. us about your findings, just don't send them to us over Discord, post them in any public places, etc.
Basically don't be a moron. You can also tell us that you sent us an email over at [our bounties site](https://bounties.vexi.cc) (just wait until its done) Basically don't be a moron. You can also tell us that you sent us an email over at [our bounties site](https://bounties.vexi.cc) (just wait until its done)

View File

@ -5,6 +5,7 @@
import { Observable } from 'rxjs' import { Observable } from 'rxjs'
import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr' import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr'
import { AuthEntity, QueueType } from './types/Types'
const URI = 'https://spookvooper.com/ExchangeHub' const URI = 'https://spookvooper.com/ExchangeHub'
const retryTime = 5 const retryTime = 5
@ -55,7 +56,7 @@ class ExchangeHub {
this.start() this.start()
} }
public async start (): Promise<void> { private async start (): Promise<void> {
console.log(`ExchangeHub: Starting connection between local and ${URI}`) console.log(`ExchangeHub: Starting connection between local and ${URI}`)
try { try {
@ -74,6 +75,34 @@ class ExchangeHub {
console.error('ExchangeHub Error: Connection closed unexpectedly', e) console.error('ExchangeHub Error: Connection closed unexpectedly', e)
await this.start() await this.start()
} }
public async sendChatMessage (message: string, accountid: string, auth: AuthEntity, ticker: string, tradeState: QueueType): Promise<any> {
return await new Promise((resolve, reject) => {
if (message === undefined || accountid === undefined || auth === undefined || ticker === undefined || tradeState === undefined) {
throw new Error('All parameters need to be set')
}
this.connection.invoke('SendMessage', accountid, auth.apikey, message, ticker, tradeState)
.then(() => {
resolve(true)
})
.catch((err) => {
reject(err)
})
})
}
public async getMessageHistory (): Promise<any> {
return await new Promise((resolve, reject) => {
this.connection.invoke('RequestHistory')
.then((val) => {
resolve(val)
})
.catch((err) => {
reject(err)
})
})
}
} }
export default ExchangeHub export default ExchangeHub

11
typings/modules/District.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import { District as DistrictType, DistrictWealthType, SenatorDistrict } from './types/Types'
import { ReturnedUser } from './interfaces/Interfaces'
declare class District {
private readonly districtName
get name (): DistrictType;
set name (name: DistrictType);
constructor (name: DistrictType);
getWealth (type: DistrictWealthType): Promise<number>;
getSenator (district?: SenatorDistrict): Promise<ReturnedUser>;
}
export default District

16
typings/modules/ExchangeHub.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { Observable } from 'rxjs'
import { AuthEntity, QueueType } from './types/Types'
declare class ExchangeHub {
private readonly connection
onOffer: Observable<unknown>
onOfferCancel: Observable<unknown>
onTradeEvent: Observable<unknown>
onMessage: Observable<unknown>
onMessageHistory: Observable<unknown>
constructor ();
private readonly start
private readonly onClosed
sendChatMessage (message: string, accountid: string, auth: AuthEntity, ticker: string, tradeState: QueueType): Promise<any>;
getMessageHistory (): Promise<any>;
}
export default ExchangeHub

12
typings/modules/Stock.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
import { QueueType } from './types/Types'
declare class Stock {
private readonly stockTicker
get ticker (): string;
set ticker (ticker: string);
constructor (ticker: string);
getValue (): Promise<any>;
getBuyPrice (): Promise<any>;
getQueueInfo (type: QueueType): Promise<any>;
getOwnerData (): Promise<any>;
}
export default Stock

12
typings/modules/TransactionHub.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
import { Observable } from 'rxjs'
declare class TransactionHub {
private readonly connection
private readonly val
fromAccount: string
toAccount: string
event: Observable<unknown>
constructor ();
start (): Promise<void>;
private readonly onClosed
}
export default TransactionHub

View File

@ -1,4 +1,4 @@
import { CreditAmount, PaymentEntity, SVStockTicker } from './types/Types' import { CreditAmount, PaymentEntity } from './types/Types'
import { ConfigUser } from './interfaces/Interfaces' import { ConfigUser } from './interfaces/Interfaces'
declare class User { declare class User {
private readonly accountid private readonly accountid
@ -10,13 +10,14 @@ declare class User {
hasDiscordRole (role: string): Promise<any>; hasDiscordRole (role: string): Promise<any>;
getDiscordRoles (): Promise<any>; getDiscordRoles (): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any>; sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any>;
getStockOffers (ticker: SVStockTicker): Promise<any>; getStockOffers (ticker: string): Promise<any>;
buyStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>; buyStock (ticker: string, amount: number, price: CreditAmount): Promise<any>;
sellStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>; sellStock (ticker: string, amount: number, price: CreditAmount): Promise<any>;
cancelOffer (orderid: number): Promise<any>; cancelOffer (orderid: number): Promise<any>;
get apikey (): string; get apikey (): string;
set apikey (apikey: string); set apikey (apikey: string);
get svid (): string; get svid (): string;
set svid (svid: string); set svid (svid: string);
hasFossPp (): boolean;
} }
export default User export default User

View File

@ -1,5 +1,7 @@
export interface EntityUser { import { DistrictWealthType, SenatorDistrict } from '../types/Types'
interface EntityUser {
svid: string svid: string
apikey: string
getUser: () => Promise<any> getUser: () => Promise<any>
getUsername: () => Promise<any> getUsername: () => Promise<any>
getBalance: () => Promise<any> getBalance: () => Promise<any>
@ -9,20 +11,64 @@ export interface EntityUser {
getStockOffers: () => Promise<any> getStockOffers: () => Promise<any>
buyStock: () => Promise<any> buyStock: () => Promise<any>
sellStock: () => Promise<any> sellStock: () => Promise<any>
setApiKey: () => void
setSvid: () => void
} }
interface EntityGroup {
export interface ConfigUser { svid: string
}
interface EntityDistrict {
name: string
getWealth: (type: DistrictWealthType) => Promise<number>
getSenator: (district: SenatorDistrict) => Promise<ReturnedUser>
}
interface ConfigUser {
svid: string svid: string
apikey?: string apikey?: string
} }
interface ConfigAuth {
export interface EntityGroup {
svid: string
}
export interface AuthConfig {
clientid: string clientid: string
clientsecret: string clientsecret: string
} }
interface ReturnedUser {
userName: string
twitch_id: string | null
discord_id: number | null
post_likes: number
comment_likes: number
nationstate: string | null
description: string | null
api_use_count: number
minecraft_id: string | null
twitch_last_message_minute: number
twitch_message_xp: number
twitch_messages: number
discord_commends: number
discord_commends_sent: number
discord_last_commend_hour: number
discord_last_commend_message: number
discord_message_xp: number
discord_message_count: number
discord_last_message_minute: number
discord_warning_count: number
discord_ban_count: number
discord_kick_count: number
discord_game_xp: number
district: string | null
id: string
name: string
credits: number
image_Url: string | null
}
interface ReturnedTransaction {
FromAccount: string
ToAccount: string
Amount: number
Detail: string
Force: boolean
IsCompleted: boolean
Tax: number
Result: {
Info: string
Succeeded: boolean
}
}
export { EntityUser, EntityGroup, EntityDistrict, ConfigUser, ConfigAuth, ReturnedUser, ReturnedTransaction }

View File

@ -1,7 +1,11 @@
import { EntityUser, AuthConfig as AuthConfigInt } from './../interfaces/Interfaces' import { EntityUser, ConfigAuth } from './../interfaces/Interfaces'
export declare type CreditAmount = string | number declare type CreditAmount = string | number
export declare type PaymentEntity = string | EntityUser declare type PaymentEntity = string | EntityUser
export declare type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X' declare type AuthEntity = EntityUser
export declare type AuthEntity = EntityUser declare type GroupMember = string | EntityUser
export declare type GroupMember = string | EntityUser declare type AuthConfig = ConfigAuth
export declare type AuthConfig = AuthConfigInt declare type District = 'Voopmont' | 'New Yam' | 'San Vooperisco' | 'Medievala' | 'Landing Cove' | 'New Spudland' | 'Vooperia City' | 'Corgi' | 'Old Yam' | 'New Vooperis' | 'The Netherlands' | 'Queensland' | 'Servers Past' | 'Los Vooperis' | 'Old King Peninsula'
declare type DistrictWealthType = 'ALL' | 'USER' | 'GROUP'
declare type SenatorDistrict = District | 'ALL'
declare type QueueType = 'BUY' | 'SELL'
export { CreditAmount, PaymentEntity, AuthEntity, GroupMember, AuthConfig, District, DistrictWealthType, SenatorDistrict, QueueType }