Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gamenet: Add fields to SvGameMsg #90

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gamenet/generate/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ def fix_network(network, version):
]

TUNE_PARAMS = ("sv", "tune", "params")
GAME_MSG = ("sv", "game", "msg")
EXTRA_PROJECTILE = ("sv", "extra", "projectile")
IS_DDNET = ("cl", "is", "ddnet")
IS_DDNET_LEGACY = ("cl", "is", "ddnet", "legacy")
for i in range(len(network.Messages)):
if network.Messages[i].name == TUNE_PARAMS:
network.Messages[i] = NetMessage("SvTuneParams", [NetTuneParam(n) for n in TUNE_PARAM_NAMES[version]])
elif network.Messages[i].name == GAME_MSG:
network.Messages[i].values.append(NetIntRange("m_GameMsg", 'GAMEMSG_TEAM_SWAP', 'GAMEMSG_GAME_PAUSED'))
network.Messages[i].values.append(NetIntAny("para_i"))
network.Messages[i].values.append(NetIntAny("para_ii"))
network.Messages[i].values.append(NetIntAny("para_iii"))
elif network.Messages[i].name == EXTRA_PROJECTILE:
network.Messages[i].values.append(NetObjectMember("projectile", ("projectile",)))
elif network.Messages[i].name in (IS_DDNET, IS_DDNET_LEGACY):
Expand Down
7 changes: 6 additions & 1 deletion gamenet/generate/spec/teeworlds-0.7.5.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,12 @@
{
"id": 21,
"name": ["sv", "game", "msg"],
"members": [],
"members": [
{"name": ["game", "msg"], "type": {"kind": "int32", "min": 0, "max": 10}},
{"name": ["para", "i"], "type": {"kind": "int32"}},
{"name": ["para", "ii"], "type": {"kind": "int32"}},
{"name": ["para", "iii"], "type": {"kind": "int32"}}
],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this JSON is supposed to be generated by gamenet/generate/loader.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean editing this line?

NetMessage("Sv_GameMsg", []),

That would differ from upstream then 🤔

https://github.com/teeworlds/teeworlds/blob/a1911c8f7d8458fb4076ef8e7651e8ef5e91ab3e/datasrc/network.py#L383

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, editing this description in loader.py, and hopefully also pull-requesting something to upstream to fix this incorrect protocol description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have no arguments so not sure how incorrect it is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incorrect in the sense that it apparently doesn't do what you want it to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so this one should be added for sure NetIntRange("m_GameMsg", 'GAMEMSG_TEAM_SWAP', 'GAMEMSG_GAME_PAUSED')

But if the parameters are also added there then that would not always be correct. The teeworlds py protocol spec does not support optional types. So they just left it empty and made it optional in c++.

"attributes": []
},
{
Expand Down
25 changes: 23 additions & 2 deletions gamenet/teeworlds-0.7/src/msg/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,12 @@ pub struct SvClientDrop<'a> {
}

#[derive(Clone, Copy)]
pub struct SvGameMsg;
pub struct SvGameMsg {
pub game_msg: enums::Gamemsg,
pub para_i: Option<i32>,
pub para_ii: Option<i32>,
pub para_iii: Option<i32>,
}

#[derive(Clone, Copy)]
pub struct DeClientEnter<'a> {
Expand Down Expand Up @@ -1486,17 +1491,33 @@ impl<'a> fmt::Debug for SvClientDrop<'a> {

impl SvGameMsg {
pub fn decode<W: Warn<Warning>>(warn: &mut W, _p: &mut Unpacker) -> Result<SvGameMsg, Error> {
let result = Ok(SvGameMsg);
let result = Ok(SvGameMsg {
game_msg: enums::Gamemsg::from_i32(_p.read_int(warn)?)?,
para_i: _p.read_int(warn).ok(),
para_ii: _p.read_int(warn).ok(),
para_iii: _p.read_int(warn).ok(),
});
_p.finish(warn);
result
}
pub fn encode<'d, 's>(&self, mut _p: Packer<'d, 's>) -> Result<&'d [u8], CapacityError> {
assert!(self.para_i.is_some());
assert!(self.para_ii.is_some());
assert!(self.para_iii.is_some());
_p.write_int(self.game_msg.to_i32())?;
_p.write_int(self.para_i.unwrap())?;
_p.write_int(self.para_ii.unwrap())?;
_p.write_int(self.para_iii.unwrap())?;
Ok(_p.written())
}
}
impl fmt::Debug for SvGameMsg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("SvGameMsg")
.field("game_msg", &self.game_msg)
.field("para_i", &self.para_i.as_ref().map(|v| v))
.field("para_ii", &self.para_ii.as_ref().map(|v| v))
.field("para_iii", &self.para_iii.as_ref().map(|v| v))
.finish()
}
}
Expand Down
Loading