public void update() { for (int i = 0; !delayUpdates && i < clients.Count; ++i) { clients[i].update(); if (!clients[i].connected()) { clients.Remove(clients[i]); --i; continue; } } if (Multiplayer.lobby) { return; } if (clients.Count == 0) { ChatMenu.chat.Add(new ChatEntry(null, "No more clients.")); Multiplayer.mode = Mode.Singleplayer; Multiplayer.server = null; return; } if (playing && Game1.player != null) { Multiplayer.doMyPlayerUpdates(0); if ((DateTime.Now - lastTimeSync).TotalMilliseconds >= 10000 /*&& Game1.timeOfDay % 100 == 0*/) // 10 seconds? Sure, why not { broadcast(new TimeSyncPacket()); lastTimeSync = DateTime.Now; } }/* * else if ( !playing && Game1.player != null ) * { * bool othersReady = true; * foreach ( Server.Client client in clients ) * { * othersReady = othersReady && ( client.stage == Client.NetStage.WaitingForStart ); * } * * if ( othersReady ) * { * playing = true; * } * }*/ }
public void update() { if (!conn.isConnected()) { ChatMenu.chat.Add(new ChatEntry(null, "You lost connection to the server.")); Multiplayer.mode = Mode.Singleplayer; Multiplayer.client = null; return; } if (tempStopUpdating) { return; } if (stage != NetStage.Waiting) { processDelayedPackets(); } if (stage == NetStage.Playing) { Multiplayer.doMyPlayerUpdates(id); } try { while (toReceive.Count > 0) { Packet packet; bool success = toReceive.TryTake(out packet); if (!success) { continue; } if (stage == NetStage.Waiting && packet.id != ID.NextDay && packet.id != ID.Chat /*&& packet.id != ID.WorldData*/) { packetDelay.Enqueue(packet); } else { packet.process(this); } } } catch (Exception e) { Log.error("Exception receiving: " + e); } }