fix(server): Fix server's referencing old player system

This commit is contained in:
Taso committed 2021-04-19 14:14:25 -04:00
1 parent 25a629a59b
commit 93fd955ae9
8 files changed
+60 -52

No files matched your search

+2 -4
View File
@@ -10,18 +10,16 @@ export const config: IServerConfig = JSON.parse(
import './db';
import 'players/player.controller';
import 'calls/calls.controller';
import 'notes/notes.controller';
import 'contacts/contacts.controller';
import './db';
import './sv_twitter';
import './sv_main';
import './sv_contacts';
import './sv_marketplace';
import './sv_bank';
import './sv_notes';
import './sv_photo';
import './sv_messages';
import './sv_match';
import './sv_call';
import { mainLogger } from './sv_logger';
export let ESX: Server = null;
+4 -4
View File
@@ -1,9 +1,9 @@
import { ESX } from './server';
import { getSource } from './functions';
import { pool } from './db';
import { Transfer, IBankCredentials, BankEvents } from '../../typings/bank';
import { getIdentifier } from './functions';
import { mainLogger } from './sv_logger';
import { getSource } from './utils/miscUtils';
import PlayerService from './players/player.service';
const bankLogger = mainLogger.child({ module: 'bank' });
@@ -77,7 +77,7 @@ async function getTransfer(transferId: number): Promise<Transfer> {
onNet(BankEvents.FETCH_TRANSACTIONS, async () => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
const _identifier = PlayerService.getIdentifier(_source);
const transfer = await fetchAllTransactions(_identifier);
emitNet(BankEvents.SEND_TRANSFERS, _source, transfer);
@@ -92,7 +92,7 @@ onNet(BankEvents.ADD_TRANSFER, async (transfer: Transfer) => {
const _source = getSource();
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
try {
const _identifier = getIdentifier(_source);
const _identifier = PlayerService.getIdentifier(_source);
await addTransfer(_identifier, transfer);
// we need to create a notification for bank. that's why i have commented out.
+3 -2
View File
@@ -1,7 +1,8 @@
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { mainLogger } from './sv_logger';
import { PhoneEvents } from '../../typings/phone';
import PlayerService from './players/player.service';
import { getSource } from './utils/miscUtils';
interface Credentials {
phone_number: string;
@@ -18,7 +19,7 @@ async function getCredentials(identifier: string): Promise<string> {
onNet('phone:getCredentials', async () => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const number = await getCredentials(identifier);
emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number);
} catch (e) {
+4 -3
View File
@@ -1,9 +1,10 @@
import { getIdentifier, getPlayer, getSource } from './functions';
import { pool } from './db';
import { mainLogger } from './sv_logger';
import { MarketplaceListing } from '../../typings/marketplace';
import { reportListingToDiscord } from './discord';
import { MarketplaceEvents } from '../../typings/marketplace';
import { getSource } from './utils/miscUtils';
import PlayerService from './players/player.service';
const selloutLogger = mainLogger.child({ module: 'sellout' });
@@ -76,7 +77,7 @@ onNet(MarketplaceEvents.FETCH_LISTING, async () => {
onNet(MarketplaceEvents.ADD_LISTING, async (listing: MarketplaceListing) => {
const _source = getSource();
try {
const player = getPlayer(_source);
const player = PlayerService.getPlayer(_source);
// This is used as username for the reports
await addListing(
@@ -107,7 +108,7 @@ onNet(MarketplaceEvents.ADD_LISTING, async (listing: MarketplaceListing) => {
onNet(MarketplaceEvents.DELETE_LISTING, async (listingId: number) => {
const pSource = getSource();
try {
const identifier = getIdentifier(pSource);
const identifier = PlayerService.getIdentifier(pSource);
await deleteListing(listingId, identifier);
+9 -8
View File
@@ -1,11 +1,12 @@
import { ResultSetHeader, RowDataPacket } from 'mysql2';
import { ResultSetHeader } from 'mysql2';
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { config } from './server';
import { Like, Match, Profile, MatchEvents, NewProfile } from '../../typings/match';
import { mainLogger } from './sv_logger';
import { generateProfileName } from './players/sv_players';
import { generateProfileName } from './utils/generateProfileName';
import { getSource } from './utils/miscUtils';
import PlayerService from './players/player.service';
const matchLogger = mainLogger.child({ module: 'match' });
const DEFAULT_IMAGE = 'https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg';
@@ -252,7 +253,7 @@ async function dispatchProfiles(identifier: string, source: number): Promise<voi
onNet(MatchEvents.INITIALIZE, async () => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
matchLogger.debug(`Initializing match for identifier: ${identifier}`);
await dispatchPlayerProfile(identifier, _source);
@@ -262,7 +263,7 @@ onNet(MatchEvents.INITIALIZE, async () => {
onNet(MatchEvents.CREATE_MY_PROFILE, async (profile: Profile) => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
matchLogger.debug(`Creating profile for identifier: ${identifier}`);
matchLogger.debug(profile);
@@ -284,7 +285,7 @@ onNet(MatchEvents.CREATE_MY_PROFILE, async (profile: Profile) => {
onNet(MatchEvents.UPDATE_MY_PROFILE, async (profile: Profile) => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
matchLogger.debug(`Updating profile for identifier: ${identifier}`);
matchLogger.debug(profile);
@@ -306,7 +307,7 @@ onNet(MatchEvents.UPDATE_MY_PROFILE, async (profile: Profile) => {
onNet(MatchEvents.SAVE_LIKES, async (likes: Like[]) => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
matchLogger.debug(`Saving likes for identifier ${identifier}`);
try {
@@ -334,7 +335,7 @@ onNet(MatchEvents.SAVE_LIKES, async (likes: Like[]) => {
onNet(MatchEvents.GET_MATCHES, async () => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
try {
const matchedProfiles = await findAllMatches(identifier);
+9 -8
View File
@@ -5,8 +5,9 @@ import {
MessageEvents,
} from '../../typings/messages';
import { pool, withTransaction } from './db';
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
import { mainLogger } from './sv_logger';
import PlayerService from './players/player.service';
import { getSource } from './utils/miscUtils';
const messageLogger = mainLogger.child({ module: 'messages' });
@@ -421,7 +422,7 @@ async function setMessageRead(groupId: string, identifier: string) {
onNet(MessageEvents.FETCH_MESSAGE_GROUPS, async () => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const messageGroups = await getFormattedMessageGroups(identifier);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS_SUCCESS, _source, messageGroups);
} catch (e) {
@@ -433,7 +434,7 @@ onNet(MessageEvents.FETCH_MESSAGE_GROUPS, async () => {
onNet(MessageEvents.CREATE_MESSAGE_GROUP, async (phoneNumbers: string[], label: string = null) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
const _identifier = PlayerService.getIdentifier(_source);
const result = await createMessageGroupsFromPhoneNumbers(_identifier, phoneNumbers, label);
if (result.error && result.allNumbersFailed) {
@@ -477,7 +478,7 @@ onNet(MessageEvents.CREATE_MESSAGE_GROUP, async (phoneNumbers: string[], label:
for (const participantId of result.identifiers) {
// we don't broadcast to the source of the event.
if (participantId !== _identifier) {
const participantPlayer = getPlayerFromIdentifier(participantId);
const participantPlayer = PlayerService.getPlayerFromIdentifier(participantId);
if (!participantPlayer) {
return;
}
@@ -501,7 +502,7 @@ onNet(MessageEvents.CREATE_MESSAGE_GROUP, async (phoneNumbers: string[], label:
onNet(MessageEvents.FETCH_MESSAGES, async (groupId: string) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
const _identifier = PlayerService.getIdentifier(_source);
const messages = await getMessages(_identifier, groupId);
emitNet(MessageEvents.FETCH_MESSAGES_SUCCESS, _source, messages);
} catch (e) {
@@ -515,7 +516,7 @@ onNet(MessageEvents.FETCH_MESSAGES, async (groupId: string) => {
onNet(MessageEvents.SEND_MESSAGE, async (groupId: string, message: string, groupName: string) => {
const _source = getSource();
try {
const _identifier = getIdentifier(_source);
const _identifier = PlayerService.getIdentifier(_source);
const userParticipants = getIdentifiersFromParticipants(groupId);
await createMessage(_identifier, groupId, message, userParticipants);
@@ -527,7 +528,7 @@ onNet(MessageEvents.SEND_MESSAGE, async (groupId: string, message: string, group
for (const participantId of userParticipants) {
// we don't broadcast to the source of the event.
if (participantId !== _identifier) {
const participantPlayer = getPlayerFromIdentifier(participantId);
const participantPlayer = PlayerService.getPlayerFromIdentifier(participantId);
if (!participantPlayer) {
return;
}
@@ -553,7 +554,7 @@ onNet(MessageEvents.SEND_MESSAGE, async (groupId: string, message: string, group
onNet(MessageEvents.SET_MESSAGE_READ, async (groupId: string) => {
const pSource = getSource();
try {
const identifier = getIdentifier(pSource);
const identifier = PlayerService.getIdentifier(pSource);
await setMessageRead(groupId, identifier);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS, pSource);
} catch (e) {
+5 -4
View File
@@ -1,7 +1,8 @@
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { GalleryPhoto, PhotoEvents } from '../../typings/photo';
import { mainLogger } from './sv_logger';
import { getSource } from './utils/miscUtils';
import PlayerService from './players/player.service';
const photoLogger = mainLogger.child({ module: 'photo' });
@@ -25,7 +26,7 @@ async function deletePhoto(photo: GalleryPhoto, identifier: string) {
onNet(PhotoEvents.UPLOAD_PHOTO, async (image: string) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const photo = await uploadPhoto(identifier, image);
emitNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, _source, photo);
} catch (e) {
@@ -38,7 +39,7 @@ onNet(PhotoEvents.UPLOAD_PHOTO, async (image: string) => {
onNet(PhotoEvents.FETCH_PHOTOS, async () => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const photos = await getPhotosByIdentifier(identifier);
emitNet(PhotoEvents.SEND_PHOTOS, _source, photos);
} catch (e) {
@@ -51,7 +52,7 @@ onNet(PhotoEvents.FETCH_PHOTOS, async () => {
onNet(PhotoEvents.DELETE_PHOTO, async (photo: GalleryPhoto) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
await deletePhoto(photo, identifier);
emitNet(PhotoEvents.DELETE_PHOTO_SUCCESS, _source);
} catch (e) {
+24 -19
View File
@@ -1,12 +1,13 @@
import { ResultSetHeader } from 'mysql2';
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { NewTweet, Tweet, Profile } from '../../typings/twitter';
import { config } from './server';
import { reportTweetToDiscord } from './discord';
import { mainLogger } from './sv_logger';
import { generateProfileName, getDefaultProfileNames } from './players/player.service';
import PlayerService from './players/player.service';
import { TwitterEvents } from '../../typings/twitter';
import { getSource } from './utils/miscUtils';
import { generateProfileName } from './utils/generateProfileName';
const twitterLogger = mainLogger.child({ module: 'twitter' });
@@ -311,19 +312,23 @@ async function doesRetweetExist(tweetId: number, identifier: string): Promise<bo
onNet(TwitterEvents.GET_OR_CREATE_PROFILE, async () => {
const _source = getSource();
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
try {
const profile = await getOrCreateProfile(identifier);
// if we got null from getOrCreateProfile it means it doesn't exist and
// we failed to create it. In this case we pass the UI some default
// profile names it can choose from
if (!profile) {
const defaultProfileNames = await getDefaultProfileNames(identifier);
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE_NULL, _source, defaultProfileNames);
} else {
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE_SUCCESS, _source, profile);
}
// profile names it can choose from.
// We should be able to comment this out as profile **should** be guranteed,
// as we create a default profile in that process.
// if (!profile) {
// const defaultProfileNames = await getDefaultProfileNames(identifier);
// emitNet(TwitterEvents.GET_OR_CREATE_PROFILE_NULL, _source, defaultProfileNames);
// } else {
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE_SUCCESS, _source, profile);
// }
} catch (e) {
twitterLogger.error(`Failed to get or create profile, ${e.message}`, {
source: _source,
@@ -335,7 +340,7 @@ onNet(TwitterEvents.GET_OR_CREATE_PROFILE, async () => {
onNet(TwitterEvents.CREATE_PROFILE, async (profile: Profile) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
await createProfile(identifier, profile.profile_name);
emitNet(TwitterEvents.CREATE_PROFILE_RESULT, _source, {
message: 'TWITTER_CREATE_PROFILE_SUCCESS',
@@ -355,7 +360,7 @@ onNet(TwitterEvents.CREATE_PROFILE, async (profile: Profile) => {
onNet(TwitterEvents.UPDATE_PROFILE, async (profile: Profile) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
await updateProfile(identifier, profile);
emitNet(TwitterEvents.UPDATE_PROFILE_RESULT, _source, {
message: 'TWITTER_EDIT_PROFILE_SUCCESS',
@@ -375,7 +380,7 @@ onNet(TwitterEvents.UPDATE_PROFILE, async (profile: Profile) => {
onNet(TwitterEvents.FETCH_TWEETS, async () => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const profile = await getProfile(identifier);
if (!profile) {
twitterLogger.warn(
@@ -397,7 +402,7 @@ onNet(TwitterEvents.FETCH_TWEETS, async () => {
onNet(TwitterEvents.FETCH_TWEETS_FILTERED, async (searchValue: string) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const profile = await getProfile(identifier);
const tweets = await fetchTweetsFiltered(profile.id, searchValue);
emitNet(TwitterEvents.FETCH_TWEETS_FILTERED_SUCCESS, _source, tweets);
@@ -412,7 +417,7 @@ onNet(TwitterEvents.FETCH_TWEETS_FILTERED, async (searchValue: string) => {
onNet(TwitterEvents.CREATE_TWEET, async (tweet: Tweet) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const createdTweet = await createTweet(identifier, tweet);
emitNet(TwitterEvents.CREATE_TWEET_BROADCAST, -1, createdTweet);
} catch (e) {
@@ -429,7 +434,7 @@ onNet(TwitterEvents.CREATE_TWEET, async (tweet: Tweet) => {
onNet(TwitterEvents.DELETE_TWEET, async (tweetId: number) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
await deleteTweet(identifier, tweetId);
emitNet(TwitterEvents.DELETE_TWEET_SUCCESS, _source);
@@ -444,7 +449,7 @@ onNet(TwitterEvents.DELETE_TWEET, async (tweetId: number) => {
onNet(TwitterEvents.TOGGLE_LIKE, async (tweetId: number) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const profile = await getOrCreateProfile(identifier);
const likeExists = await doesLikeExist(profile.id, tweetId);
if (likeExists) {
@@ -464,7 +469,7 @@ onNet(TwitterEvents.TOGGLE_LIKE, async (tweetId: number) => {
onNet(TwitterEvents.RETWEET, async (tweetId: number) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
// alert the player that they have already retweeted
// this post (or that they are the original poster)
@@ -495,7 +500,7 @@ onNet(TwitterEvents.RETWEET, async (tweetId: number) => {
onNet(TwitterEvents.REPORT, async (tweetId: number) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
const identifier = PlayerService.getIdentifier(_source);
const profile = await getProfile(identifier);
const tweet = await getTweet(profile.id, tweetId);