mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39:24 +01:00
Add region handling for the network as well
This commit is contained in:
parent
65f0844cae
commit
8af1a6c773
@ -685,7 +685,7 @@ bool Network::MarshalData(NetworkUpdate *p)
|
|||||||
peer->is_master = htons(peer->is_master);
|
peer->is_master = htons(peer->is_master);
|
||||||
peer->server_id = htonl(peer->server_id);
|
peer->server_id = htonl(peer->server_id);
|
||||||
peer->version = htonl(peer->version);
|
peer->version = htonl(peer->version);
|
||||||
peer->avatar = htonl(peer->avatar);
|
peer->avatar = htons(peer->avatar);
|
||||||
peer->screenshot_key = htonl(peer->screenshot_key);
|
peer->screenshot_key = htonl(peer->screenshot_key);
|
||||||
}
|
}
|
||||||
lp->n_peers = htonl(lp->n_peers);
|
lp->n_peers = htonl(lp->n_peers);
|
||||||
@ -809,7 +809,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
|
|||||||
peer->is_master = ntohs(peer->is_master);
|
peer->is_master = ntohs(peer->is_master);
|
||||||
peer->server_id = ntohl(peer->server_id);
|
peer->server_id = ntohl(peer->server_id);
|
||||||
peer->version = ntohl(peer->version);
|
peer->version = ntohl(peer->version);
|
||||||
peer->avatar = ntohl(peer->avatar);
|
peer->avatar = ntohs(peer->avatar);
|
||||||
peer->screenshot_key = ntohl(peer->screenshot_key);
|
peer->screenshot_key = ntohl(peer->screenshot_key);
|
||||||
}
|
}
|
||||||
lp->your_port = ntohs(lp->your_port);
|
lp->your_port = ntohs(lp->your_port);
|
||||||
@ -1059,6 +1059,7 @@ bool Network::ConnectToBroker()
|
|||||||
pi->key = ThePrefs.NetworkKey;
|
pi->key = ThePrefs.NetworkKey;
|
||||||
pi->version = FRODO_NETWORK_PROTOCOL_VERSION;
|
pi->version = FRODO_NETWORK_PROTOCOL_VERSION;
|
||||||
pi->avatar = ThePrefs.NetworkAvatar;
|
pi->avatar = ThePrefs.NetworkAvatar;
|
||||||
|
pi->region = ThePrefs.NetworkRegion;
|
||||||
pi->screenshot_key = 0;
|
pi->screenshot_key = 0;
|
||||||
|
|
||||||
strcpy((char*)pi->name, ThePrefs.NetworkName);
|
strcpy((char*)pi->name, ThePrefs.NetworkName);
|
||||||
|
@ -150,7 +150,9 @@ struct NetworkUpdatePeerInfo
|
|||||||
uint32 server_id; /* Used by the server */
|
uint32 server_id; /* Used by the server */
|
||||||
uint32 version; /* Version number */
|
uint32 version; /* Version number */
|
||||||
|
|
||||||
uint32 avatar; /* Hash of the avatar */
|
uint8 region; /* Europe, africa etc */
|
||||||
|
uint8 d; /* Dummy */
|
||||||
|
uint16 avatar; /* Hash of the avatar */
|
||||||
uint32 screenshot_key; /* Key number of the screenshot */
|
uint32 screenshot_key; /* Key number of the screenshot */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ private:
|
|||||||
int NetworkPort;
|
int NetworkPort;
|
||||||
|
|
||||||
int NetworkKey;
|
int NetworkKey;
|
||||||
uint32 NetworkAvatar;
|
uint16 NetworkAvatar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ public:
|
|||||||
{
|
{
|
||||||
this->name = (const char*)xstrdup((char*)pi->name);
|
this->name = (const char*)xstrdup((char*)pi->name);
|
||||||
this->scr = NULL;
|
this->scr = NULL;
|
||||||
this->region = 0;
|
this->region = pi->region;
|
||||||
|
if (this->region > REGION_ANTARTICA)
|
||||||
|
this->region = REGION_UNKNOWN;
|
||||||
this->scr_key = pi->screenshot_key;
|
this->scr_key = pi->screenshot_key;
|
||||||
this->public_port = pi->public_port;
|
this->public_port = pi->public_port;
|
||||||
this->private_port = pi->private_port;
|
this->private_port = pi->private_port;
|
||||||
@ -113,7 +115,7 @@ public:
|
|||||||
this->pi_messages[1] = " ";
|
this->pi_messages[1] = " ";
|
||||||
this->pi_messages[2] = "Region:";
|
this->pi_messages[2] = "Region:";
|
||||||
this->pi_messages[3] = " ";
|
this->pi_messages[3] = " ";
|
||||||
this->pi_messages[4] = "Vobb:";
|
this->pi_messages[4] = " "; /* Maybe add something here later */
|
||||||
this->pi_messages[5] = " ";
|
this->pi_messages[5] = " ";
|
||||||
|
|
||||||
if (this->pi)
|
if (this->pi)
|
||||||
|
@ -20,6 +20,18 @@ ACK = 94 # Yep
|
|||||||
REGISTER_DATA = 90
|
REGISTER_DATA = 90
|
||||||
STOP = 55 # No more packets
|
STOP = 55 # No more packets
|
||||||
|
|
||||||
|
# Network regions
|
||||||
|
REGION_UNKNOWN = 0
|
||||||
|
REGION_EUROPE = 1
|
||||||
|
REGION_AFRICA = 2
|
||||||
|
REGION_NORTH_AMERICA = 3
|
||||||
|
REGION_SOUTH_AMERICA = 4
|
||||||
|
REGION_MIDDLE_EAST = 5
|
||||||
|
REGION_SOUTH_ASIA = 6
|
||||||
|
REGION_EAST_ASIA = 7
|
||||||
|
REGION_OCEANIA = 8
|
||||||
|
REGION_ANTARTICA = 9
|
||||||
|
|
||||||
# Flags in list peers packet
|
# Flags in list peers packet
|
||||||
NETWORK_UPDATE_LIST_PEERS_IS_CONNECT = 1
|
NETWORK_UPDATE_LIST_PEERS_IS_CONNECT = 1
|
||||||
|
|
||||||
@ -35,6 +47,19 @@ pkt_type_to_str = {
|
|||||||
REGISTER_DATA : "register-data",
|
REGISTER_DATA : "register-data",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
region_to_str = {
|
||||||
|
REGION_UNKNOWN : "Unknown",
|
||||||
|
REGION_EUROPE : "Europe",
|
||||||
|
REGION_AFRICA : "Africa",
|
||||||
|
REGION_NORTH_AMERICA : "North america",
|
||||||
|
REGION_SOUTH_AMERICA : "South america",
|
||||||
|
REGION_MIDDLE_EAST : "Middle east",
|
||||||
|
REGION_SOUTH_ASIA : "South asia",
|
||||||
|
REGION_EAST_ASIA : "East asia",
|
||||||
|
REGION_OCEANIA : "Oceania",
|
||||||
|
REGION_ANTARTICA : "Antartica",
|
||||||
|
}
|
||||||
|
|
||||||
def log(pri, msg, echo):
|
def log(pri, msg, echo):
|
||||||
syslog.syslog(pri, msg)
|
syslog.syslog(pri, msg)
|
||||||
if True:
|
if True:
|
||||||
@ -200,6 +225,7 @@ class ConnectToBrokerPacket(Packet):
|
|||||||
self.name = ""
|
self.name = ""
|
||||||
self.server_id = 0
|
self.server_id = 0
|
||||||
self.avatar = 0
|
self.avatar = 0
|
||||||
|
self.region = REGION_UNKNOWN
|
||||||
self.screenshot_key = -1
|
self.screenshot_key = -1
|
||||||
|
|
||||||
def demarshal_from_data(self, data):
|
def demarshal_from_data(self, data):
|
||||||
@ -214,7 +240,8 @@ class ConnectToBrokerPacket(Packet):
|
|||||||
self.name = self.name[0:self.name.find('\0')]
|
self.name = self.name[0:self.name.find('\0')]
|
||||||
|
|
||||||
if self.version >= 4:
|
if self.version >= 4:
|
||||||
self.avatar = struct.unpack(">L", data[88:92])[0]
|
self.region = struct.unpack(">B", data[88:89])[0]
|
||||||
|
self.avatar = struct.unpack(">H", data[90:92])[0]
|
||||||
self.screenshot_key = struct.unpack(">L", data[92:96])[0]
|
self.screenshot_key = struct.unpack(">L", data[92:96])[0]
|
||||||
|
|
||||||
def get_key(self):
|
def get_key(self):
|
||||||
@ -223,6 +250,9 @@ class ConnectToBrokerPacket(Packet):
|
|||||||
def get_avatar(self):
|
def get_avatar(self):
|
||||||
return self.avatar
|
return self.avatar
|
||||||
|
|
||||||
|
def get_region(self):
|
||||||
|
return self.region
|
||||||
|
|
||||||
def get_screenshot_key(self):
|
def get_screenshot_key(self):
|
||||||
return self.screenshot_key
|
return self.screenshot_key
|
||||||
|
|
||||||
@ -241,6 +271,8 @@ class ListPeersPacket(Packet):
|
|||||||
self.size = self.size + 24
|
self.size = self.size + 24
|
||||||
self.version = version
|
self.version = version
|
||||||
self.flags = flags
|
self.flags = flags
|
||||||
|
self.region = REGION_UNKNOWN
|
||||||
|
self.avatar = 0
|
||||||
|
|
||||||
def add_peer(self, peer):
|
def add_peer(self, peer):
|
||||||
self.peers.append(peer)
|
self.peers.append(peer)
|
||||||
@ -264,7 +296,7 @@ class ListPeersPacket(Packet):
|
|||||||
peer.is_master, name,
|
peer.is_master, name,
|
||||||
0, peer.id, self.version)
|
0, peer.id, self.version)
|
||||||
if self.version >= 4:
|
if self.version >= 4:
|
||||||
out = out + struct.pack(">LL", peer.avatar, peer.screenshot_key)
|
out = out + struct.pack(">BxHL", peer.region, peer.avatar, peer.screenshot_key)
|
||||||
|
|
||||||
return Packet.marshal(self) + out
|
return Packet.marshal(self) + out
|
||||||
|
|
||||||
@ -277,6 +309,9 @@ class DummyPeer:
|
|||||||
self.key = 0
|
self.key = 0
|
||||||
self.is_master = 0
|
self.is_master = 0
|
||||||
self.id = 0
|
self.id = 0
|
||||||
|
self.avatar = 0
|
||||||
|
self.region = 0
|
||||||
|
|
||||||
|
|
||||||
class Peer:
|
class Peer:
|
||||||
def __init__(self, addr, srv, id):
|
def __init__(self, addr, srv, id):
|
||||||
@ -300,6 +335,7 @@ class Peer:
|
|||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
self.avatar = 0
|
self.avatar = 0
|
||||||
|
self.region = 0
|
||||||
self.screenshot_key = -1
|
self.screenshot_key = -1
|
||||||
self.data_key = srv.get_data_key()
|
self.data_key = srv.get_data_key()
|
||||||
|
|
||||||
@ -322,13 +358,19 @@ class Peer:
|
|||||||
lp = ListPeersPacket(pkt.version)
|
lp = ListPeersPacket(pkt.version)
|
||||||
lp.add_peer(DummyPeer("Your frodo is too old."))
|
lp.add_peer(DummyPeer("Your frodo is too old."))
|
||||||
lp.add_peer(DummyPeer("download a new version at"))
|
lp.add_peer(DummyPeer("download a new version at"))
|
||||||
lp.add_peer(DummyPeer("http://frodo-wii.googlecode.com"))
|
lp.add_peer(DummyPeer("http://www.c64-network.org"))
|
||||||
log_info("Version too old, sending upgrade notice to %s:%d" %
|
log_info("Version too old, sending upgrade notice to %s:%d" %
|
||||||
(self.addr[0], self.addr[1]) )
|
(self.addr[0], self.addr[1]) )
|
||||||
self.send_packet(lp.marshal())
|
self.send_packet(lp.marshal())
|
||||||
return
|
return
|
||||||
|
|
||||||
self.avatar = pkt.get_avatar()
|
self.avatar = pkt.get_avatar()
|
||||||
|
self.region = pkt.get_region()
|
||||||
|
if self.region != REGION_UNKNOWN and self.country == "Unknown location":
|
||||||
|
try:
|
||||||
|
self.country = region_to_str[self.region]
|
||||||
|
except KeyError, e:
|
||||||
|
self.country = "Unknown location"
|
||||||
self.screenshot_key = pkt.get_screenshot_key() + self.data_key
|
self.screenshot_key = pkt.get_screenshot_key() + self.data_key
|
||||||
|
|
||||||
self.srv.log_connection(self.name, self.country)
|
self.srv.log_connection(self.name, self.country)
|
||||||
|
Loading…
Reference in New Issue
Block a user