the-marenga / sf-api

Manage Shakes & Fidget characters via simple commands. Handles encryption, response parsing and everything else for you
MIT License
17 stars 3 forks source link

Crash on login because of sfgames server bar response #62

Closed tiquis0290 closed 5 months ago

tiquis0290 commented 6 months ago

For some reason after expedition normally played in official sfapp, server responds with only 4 long crossroad array and when parsing data through GameState::new(), it crashes because its rightfully expects 5 long array

i could chatch the error but i dont really want to parse it by my self, fix is to manually start expedition, but i will be happier for something automatic

err: thread 'main' panicked at .../sf-api-0.1.3/src/gamestate/mod.rs:877:69: index out of bounds: the len is 4 but the index is 4

raw response: .../-5/0/1&expeditioncrossroad:21/-2/51/3&expeditionmonster:-32/...

868"expeditioncrossroad" => { 869 // 3/3/132/0/2/2 871 let data: Vec = val.into_list("cross")?; 872 let exp = self 873 .tavern 874 .expedition 875 .get_or_insert_with(Default::default); 876 exp.crossroads = [0, 2, 4].map(|pos| { 877 let typ = match FromPrimitive::from_i64(data[pos]) { 878 Some(x) => x, 879 None => { 880 warn!( 881 "Unknown crossroad enc: {} for {}", 882 data[pos], pos 883 ); 884 ExpeditionThing::Unknown 885 } 886 }; 887 let heroism = soft_into(data[pos + 1], "e heroism", 0); 888 ExpeditionEncounter { typ, heroism } 889 });

the-marenga commented 6 months ago

I guess I can never trust the server responses ever... The best solution would probably be to have the data[pos] be a data.get(pos) and map the None result to ExpeditionThing::Unknown.

More broadly, I should probably go through all occurences of using the index operator [] and replace all of them. Panicing should never happen anywhere just because the server sends something unexpected