if (reliable)
{
out->Write(out_reliable.size());
while(out_reliable.size()>0)
{
AppFrame::actions::Message* msg = out_reliable[0];
if (message_map.find(msg->getID()) != message_map.end())
{
int creator_id = message_map[msg->getID()];
out->Write(creator_id);
msg->serialize(out);
}
delete msg;
out_reliable.erase(out_reliable.begin());
}
} else
{
out->Write(out_unreliable.size());
while(out_unreliable.size()>0)
{
AppFrame::actions::Message* msg = out_unreliable[0];
if (message_map.find(msg->getID()) != message_map.end())
{
int creator_id = message_map[msg->getID()];
out->Write(creator_id);
msg->serialize(out);
}
delete msg;
out_unreliable.erase(out_unreliable.begin());
}
}
ICAgIGlmIChyZWxpYWJsZSkKICAgIHsKICAgICAgICBvdXQtPldyaXRlKG91dF9yZWxpYWJsZS5zaXplKCkpOwogICAgICAgIHdoaWxlKG91dF9yZWxpYWJsZS5zaXplKCk+MCkKICAgICAgICB7CiAgICAgICAgICAgIEFwcEZyYW1lOjphY3Rpb25zOjpNZXNzYWdlKiBtc2cgPSBvdXRfcmVsaWFibGVbMF07CgogICAgICAgICAgICBpZiAobWVzc2FnZV9tYXAuZmluZChtc2ctPmdldElEKCkpICE9IG1lc3NhZ2VfbWFwLmVuZCgpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpbnQgY3JlYXRvcl9pZCA9IG1lc3NhZ2VfbWFwW21zZy0+Z2V0SUQoKV07CiAgICAgICAgICAgICAgICBvdXQtPldyaXRlKGNyZWF0b3JfaWQpOwogICAgICAgICAgICAgICAgbXNnLT5zZXJpYWxpemUob3V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZWxldGUgbXNnOwogICAgICAgICAgICBvdXRfcmVsaWFibGUuZXJhc2Uob3V0X3JlbGlhYmxlLmJlZ2luKCkpOwogICAgICAgIH0KICAgIH0gZWxzZQogICAgewogICAgICAgIG91dC0+V3JpdGUob3V0X3VucmVsaWFibGUuc2l6ZSgpKTsKICAgICAgICB3aGlsZShvdXRfdW5yZWxpYWJsZS5zaXplKCk+MCkKICAgICAgICB7CiAgICAgICAgICAgIEFwcEZyYW1lOjphY3Rpb25zOjpNZXNzYWdlKiBtc2cgPSBvdXRfdW5yZWxpYWJsZVswXTsKCiAgICAgICAgICAgIGlmIChtZXNzYWdlX21hcC5maW5kKG1zZy0+Z2V0SUQoKSkgIT0gbWVzc2FnZV9tYXAuZW5kKCkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBjcmVhdG9yX2lkID0gbWVzc2FnZV9tYXBbbXNnLT5nZXRJRCgpXTsKICAgICAgICAgICAgICAgIG91dC0+V3JpdGUoY3JlYXRvcl9pZCk7CiAgICAgICAgICAgICAgICBtc2ctPnNlcmlhbGl6ZShvdXQpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGRlbGV0ZSBtc2c7CiAgICAgICAgICAgIG91dF91bnJlbGlhYmxlLmVyYXNlKG91dF91bnJlbGlhYmxlLmJlZ2luKCkpOwogICAgICAgIH0KICAgIH0=