public override void process(Server server, Server.Client client) { Log.trace("Got version packet"); if (client.stage != Server.Client.NetStage.VerifyingVersion) { Log.debug("Got version packet at wrong stage"); //return; } if (version == Multiplayer.PROTOCOL_VERSION) { client.stage = Server.Client.NetStage.WaitingForFarmerInfo; if (!client.sentId) { Log.trace("Sending ID packet " + client.id); client.send(new YourIDPacket(client.id)); client.sentId = true; } } else { Log.trace("Bad version from client " + client.id); client.stageFailed = true; } }
public override void process(Server server, Server.Client client) { if (version == Multiplayer.PROTOCOL_VERSION) { client.stage = Server.Client.NetStage.WaitingForFarmerInfo; client.send(new YourIDPacket(client.id)); } else { client.stageFailed = true; } }
public override void process(Server server, Server.Client client) { Log.debug("Got farmer data for client " + client.id); //SFarmer old = client.farmer; SaveGame theirs = (SaveGame)SaveGame.serializer.Deserialize(Util.stringStream(xml)); if (client.farmer == null) { ChatMenu.chat.Add(new ChatEntry(null, theirs.player.name + " has connected.")); server.broadcast(new ChatPacket(255, theirs.player.name + " has connected."), client.id); String str = "Currently playing: "; str += NewLoadMenu.pendingSelected.name; foreach (Server.Client other in server.clients) { if (other == client || other.farmer == null) { continue; } str += ", " + other.farmer.name; } client.send(new ChatPacket(255, str)); } client.farmerXml = Util.serialize <SFarmer>(theirs.player); client.farmer = theirs.player; client.farmer.uniqueMultiplayerID += 1 + client.id; NewSaveGame.loadDataToFarmer(client.farmer); client.farmer.FarmerSprite.setOwner(client.farmer); Game1.player.FarmerSprite.setOwner(Game1.player); //if(!server.playing) //if (server.playing) client.farmer = old; // About second-day-sleeping crashes: // So just adding the location directly puts the raw deserialized one into the game. // The raw deserialized one doesn't have the tiles and stuff loaded. Just the game data. // I think this is why vanilla copies data over in loadDataToLocations instead of using // the loaded objects directly. Why not just postpone loading until later, I don't know. // // So, when the second day begins, otherFarmer.currentLocation was still set to the // previous day's farm house[*]. On day two, the 'good' one[**] was removed, so when they go // back in, the bad one is used. Basically, I need to make them all the 'good' one. // For now, I'm just going to reload the needed data for this client's farmhouse. // I'll figure out how to do it 'properly' later. Maybe. (My mind is muddled today.) // // [*] Looking at addFixedLocationToOurWorld now you'll see that this isn't the case. // I added the part about fixing SFarmer.currentLocation as I was going through this // thought process. So things will break more obviously if something like this happens // again. // // [**] The first day's farmhouse is okay because in loadDataToLocations, (called in // NewSaveGame.getLoadEnumerator), the map is reloaded from FarmHouse_setMapForUpgradeLevel. // If CO-OP weren't on, worse things would happen, because things besides the farm house // would need loading (see Multiplayer.isPlayerUnique). The client doesn't have this // issue because they do the whole loading process each day anyways. // // Of course, the whole second-day-crash doesn't happen when I test it on localhost. Hence // why this was so annoying. And probably why I documented all this. foreach (GameLocation theirLoc in theirs.locations) { if (theirLoc.name == "FarmHouse") { NewSaveGame.FarmHouse_setMapForUpgradeLevel(theirLoc as FarmHouse); } } fixPetDuplicates(theirs); Multiplayer.fixLocations(theirs.locations, client.farmer, addFixedLocationToOurWorld, client); foreach (string mail in Multiplayer.checkMail) { if (client.farmer.mailForTomorrow.Contains(mail)) { if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail)) { SaveGame.loaded.player.mailForTomorrow.Add(mail); } if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail)) { Game1.player.mailForTomorrow.Add(mail); } } if (client.farmer.mailForTomorrow.Contains(mail + "%&NL&%")) { if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail + "%&NL&%")) { SaveGame.loaded.player.mailForTomorrow.Add(mail + "%&NL&%"); } if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail + "%&NL&%")) { Game1.player.mailForTomorrow.Add(mail + "%&NL&%"); } } } client.stage = Server.Client.NetStage.WaitingForStart; }