diff --git a/popn@asphyxia/handler/eclale.ts b/popn@asphyxia/handler/eclale.ts index 7540fed..6213953 100644 --- a/popn@asphyxia/handler/eclale.ts +++ b/popn@asphyxia/handler/eclale.ts @@ -283,7 +283,7 @@ const getProfile = async (refid: string, name?: string) => { result: K.ITEM('s8', 0), account: { name: K.ITEM('str', profile.name), - g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'), + g_pm_id: K.ITEM('str', profile.friendId), staff: K.ITEM('s8', 0), item_type: K.ITEM('s16', 0), item_id: K.ITEM('s16', 0), @@ -476,7 +476,7 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise { let player: any = { base: { name: K.ITEM('str', profile.name), - g_pm_id: K.ITEM('str', '1234-5678'), + g_pm_id: K.ITEM('str', profile.friendId), staff: K.ITEM('s8', 0), is_conv: K.ITEM('s8', -1), my_best: K.ARRAY('s16', myBest), @@ -215,7 +215,7 @@ export const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Prom result.friend.push({ open: K.ITEM('s8', 1), - g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'), + g_pm_id: K.ITEM('str', profile.friendId), name: K.ITEM('str', profile.name), chara: K.ITEM('s16', params.params.chara || -1), clear_medal: K.ARRAY('u16', scores.clear_medal), diff --git a/popn@asphyxia/handler/lapistoria.ts b/popn@asphyxia/handler/lapistoria.ts index 659a298..a90eb07 100644 --- a/popn@asphyxia/handler/lapistoria.ts +++ b/popn@asphyxia/handler/lapistoria.ts @@ -124,7 +124,7 @@ const getProfile = async (refid: string, name?: string) => { result: K.ITEM('s8', 0), account: { name: K.ITEM('str', profile.name), - g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'), + g_pm_id: K.ITEM('str', profile.friendId), staff: K.ITEM('s8', 0), is_conv: K.ITEM('s8', 0), item_type: K.ITEM('s16', 0), @@ -435,7 +435,7 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise { let player: any = { base: { name: K.ITEM('str', profile.name), - g_pm_id: K.ITEM('str', '1234-5678'), + g_pm_id: K.ITEM('str', profile.friendId), staff: K.ITEM('s8', 0), is_conv: K.ITEM('s8', -1), collabo: K.ITEM('u8', 255), @@ -250,7 +250,7 @@ export const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Prom result.friend.push({ open: K.ITEM('s8', 1), - g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'), + g_pm_id: K.ITEM('str', profile.friendId), name: K.ITEM('str', profile.name), chara: K.ITEM('s16', params.params.chara || -1), hair: K.ITEM('u8', params.params.hair || 0), diff --git a/popn@asphyxia/handler/tunestreet.ts b/popn@asphyxia/handler/tunestreet.ts index 7c12c4f..63c58b3 100644 --- a/popn@asphyxia/handler/tunestreet.ts +++ b/popn@asphyxia/handler/tunestreet.ts @@ -106,19 +106,6 @@ export const getProfile = async (refid: string, name?: string) => { binary_profile[15] = _.get(params, `params.last_play_flag`, 0) & 0xFF; binary_profile[16] = _.get(params, `params.medal_and_friend`, 0) & 0xFF; - let friendId = profile.friendId; - if (friendId == undefined || friendId == null) { - let check = null; - do { - friendId = ""; - for (let i = 0; i < 12; i++) { - friendId += Math.floor(Math.random() * 10); - } - profile.friendId = friendId; - let check = await DB.FindOne(null, { collection: 'profile', friendId }); - } while(check != undefined && check != null); - await utils.writeProfile(refid, profile); - } let friendIdBinary = U.EncodeString(profile.friendId, 'shift_jis'); for (let i = 0; i < friendIdBinary.length || i < 12; i++) { binary_profile[17 + i] = friendIdBinary[i]; diff --git a/popn@asphyxia/handler/usaneko.ts b/popn@asphyxia/handler/usaneko.ts index 95a5a4e..46fd825 100644 --- a/popn@asphyxia/handler/usaneko.ts +++ b/popn@asphyxia/handler/usaneko.ts @@ -324,7 +324,7 @@ const getProfile = async (refid: string, version: string, name?: string) => { result: K.ITEM('s8', 0), account: { name: K.ITEM('str', profile.name), - g_pm_id: K.ITEM('str', 'ASPHYXIAPLAY'), + g_pm_id: K.ITEM('str', profile.friendId), staff: K.ITEM('s8', 0), item_type: K.ITEM('s16', 0), item_id: K.ITEM('s16', 0), @@ -654,7 +654,7 @@ const friend = async (req: EamuseInfo, data: any, send: EamuseSend): Promise } export const readProfile = async (refid: string): Promise => { - const profile = await DB.FindOne(refid, { collection: 'profile' }); - if (profile !== undefined && profile !== null && profile.dataVersion !== CURRENT_DATA_VERSION) { - return await doConvert(profile); + let profile = await DB.FindOne(refid, { collection: 'profile' }); + if (profile !== undefined && profile !== null) { + if(profile.dataVersion !== CURRENT_DATA_VERSION) { + profile = await doConvert(profile); + } + if(profile.friendId == undefined || profile.friendId == null) { + profile.friendId = await generateFriendId(); + await writeProfile(refid, profile); + } } - return profile || { collection: 'profile', name: 'ゲスト', friendId: null, dataVersion: CURRENT_DATA_VERSION }; + return profile || { collection: 'profile', name: 'ゲスト', friendId: await generateFriendId(), dataVersion: CURRENT_DATA_VERSION }; +} + +const generateFriendId = async (): Promise => { + let friendId; + let check = null; + do { + friendId = ""; + for (let i = 0; i < 12; i++) { + friendId += Math.floor(Math.random() * 10); + } + check = await DB.FindOne(null, { collection: 'profile', friendId }); + } while(check != undefined && check != null); + return friendId; } export const writeProfile = async (refid: string, profile: Profile) => {