Skip to content

Commit

Permalink
Updated for 37506
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Nov 20, 2024
1 parent 97d7400 commit f0c2df9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion GuildWarsPartySearch.Bot/Dependencies/Headquarter
2 changes: 1 addition & 1 deletion GuildWarsPartySearch.Bot/Gw.build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
37449
37506
24 changes: 18 additions & 6 deletions GuildWarsPartySearch.NodeJSServer/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ function reassign_bot_clients(request) {
return;
assign_bot(available_bots_to_assign[0], map_id, district_region);
}

check_and_assign(14, district_regions.International);

if(isEuPrimeTime()) {
check_and_assign(map_ids.Embark_Beach, district_regions.Europe);
check_and_assign(map_ids.Domain_of_Anguish, district_regions.Europe);
Expand Down Expand Up @@ -500,16 +503,22 @@ function on_updated_parties(ws, data) {

let map_count_changed = false;

data.parties.filter((party_json) => {
return !is_quarantine_hit(party_json.message || party_json[party_json_keys['message']] || '');
}).forEach((changed_party_info) => {
data.parties.forEach((changed_party_info) => {
const party_id = to_number(changed_party_info.party_id || changed_party_info[party_json_keys['party_id']]);
const message = changed_party_info.message || changed_party_info[party_json_keys['message']] || '';
const remove = changed_party_info.r || is_quarantine_hit(message);
/**
*
* @type {PartySearch | null}
*/
let existing_party = existing_parties.find((party) => {
return party.party_id === party_id;
});
if(changed_party_info.r) {
remove_party(existing_party);
map_count_changed = true;
if(remove) {
if(existing_party) {
remove_party(existing_party);
map_count_changed = true;
}
return;
}
if(!existing_party) {
Expand All @@ -521,6 +530,9 @@ function on_updated_parties(ws, data) {
map_count_changed = true;
return;
}
// Create a copy to validate the update() before doing the same to the existing party
let party_copy = new PartySearch(existing_party.toJSON());
party_copy.update(changed_party_info);
existing_party.update(changed_party_info);
});

Expand Down
57 changes: 54 additions & 3 deletions GuildWarsPartySearch.NodeJSServer/src/js/PartySearch.class.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,65 @@ export class PartySearch {
this.party_size = to_number(json.party_size || json[party_json_keys['party_size']] || 1);
this.hero_count = to_number(json.hero_count || json[party_json_keys['hero_count']] || 0);
this.level = to_number(json.level || json[party_json_keys['level']] || 20);
this.search_type = to_number(json.search_type || json[party_json_keys['search_type']]);
this.search_type = to_number(json.search_type || json[party_json_keys['search_type']] || -1);
this.primary = to_number(json.primary || json[party_json_keys['primary']] || 0);
this.secondary = to_number(json.secondary || json[party_json_keys['secondary']] || 0);
this.district_number = to_number(json.district_number || json[party_json_keys['district_number']] || 1);
this.district_region = to_number(json.district_region || json[party_json_keys['district_region']] || 0);
this.district_language = to_number(json.district_language || json.language || json[party_json_keys['district_language']] || 0);
this.map_id = to_number(json.map_id || json[party_json_keys['map_id']] || 0);

this.district = json.district || json[party_json_keys['district']] || district_from_region(this.district_region);

const hash = json.h || json.hash;
if(hash) {
this.from_party_hash(hash);
}

this.validate();

this.district = json.district || json[party_json_keys['district']] || district_from_region(this.district_region);

}
to_party_hash() {
const a = 'A'.charCodeAt(0);
return [
String.fromCharCode(this.map_id + a),
String.fromCharCode(this.district_region + a),
String.fromCharCode(this.district_number + a),
String.fromCharCode(this.search_type + a),
String.fromCharCode(this.primary + a),
String.fromCharCode(this.party_size + a),
String.fromCharCode(this.hero_count + a),
String.fromCharCode(this.hardmode + a),
String.fromCharCode(this.language + a),
String.fromCharCode(this.secondary + a),
String.fromCharCode(this.level + a),
this.sender,
'|',
this.message
].join('');
}
from_party_hash(str) {
assert(typeof str === 'string' && str.length >= 11);
const a = 'A'.charCodeAt(0);
this.map_id = str.charCodeAt(0) - a;
this.district_region = str.charCodeAt(1) - a;
this.district_number = str.charCodeAt(2) - a;
this.search_type = str.charCodeAt(3) - a;
this.primary = str.charCodeAt(4) - a;
this.party_size = str.charCodeAt(5) - a;
this.hero_count = str.charCodeAt(6) - a;
this.hardmode = str.charCodeAt(7) - a;
this.language = str.charCodeAt(8) - a;
this.secondary = str.charCodeAt(9) - a;
this.district_number = str.charCodeAt(10) - a;
this.level = str.charCodeAt(11) - a;

const sender_end = str.indexOf('|',12);
assert(sender_end > 12);
this.sender = str.substr(12,sender_end - 12);
this.message = str.substr(sender_end + 1);
this.validate();
}

update(json) {
Expand All @@ -65,6 +113,9 @@ export class PartySearch {
if(json.hasOwnProperty(key))
this[key] = to_number(json[key]);
},this);
if(json.h && typeof json.h === 'string') {
this.from_party_hash(json.h);
}
this.validate();
}

Expand Down Expand Up @@ -120,7 +171,7 @@ export class PartySearch {
validate() {
//assert(typeof this.client_id === 'string' && this.client_id.length);
assert(typeof this.message === 'string');
assert(typeof this.sender === 'string' && this.sender.length);
assert(typeof this.sender === 'string' && this.sender.length && this.sender.length < 20);
//assert(typeof this.party_id === 'number' && this.party_size > 0);
assert(typeof this.party_size === 'number' && this.party_size > 0);
assert(typeof this.hero_count === 'number' && this.hero_count < this.party_size);
Expand Down

0 comments on commit f0c2df9

Please sign in to comment.