void LeaveServer(string chatMsg, string discMsg, bool isKick, bool sync = false) { if (leftServer || IsSuper) { return; } leftServer = true; CriticalTasks.Clear(); ZoneIn = null; // Disconnected before sent handshake if (name == null) { if (Socket != null) { Socket.Close(); } Logger.Log(LogType.UserActivity, "{0} disconnected.", IP); return; } Server.reviewlist.Remove(name); try { if (Socket.Disconnected) { PlayerInfo.Online.Remove(this); return; } // FlyBuffer.Clear(); LastAction = DateTime.UtcNow; IsAfk = false; isFlying = false; if (weapon != null) { weapon.Disable(); } if (chatMsg != null) { chatMsg = Colors.Escape(chatMsg); } discMsg = Colors.Escape(discMsg); string kickPacketMsg = ChatTokens.Apply(discMsg, this); Send(Packet.Kick(kickPacketMsg, hasCP437), sync); Socket.Disconnected = true; ZoneIn = null; if (isKick) { TimesBeenKicked++; } if (!loggedIn) { PlayerInfo.Online.Remove(this); Logger.Log(LogType.UserActivity, "{0} ({1}) disconnected. ({2})", truename, IP, discMsg); return; } Entities.DespawnEntities(this, false); ShowDisconnectInChat(chatMsg, isKick); SaveStats(); PlayerInfo.Online.Remove(this); OnPlayerDisconnectEvent.Call(this, discMsg); level.AutoUnload(); Dispose(); } catch (Exception e) { Logger.LogError("Error disconnecting player", e); } finally { Socket.Close(); } }
/// <summary> Calls SetModel, then broadcasts the new model to players. </summary> public void UpdateModel(string model) { SetModel(model); Entities.BroadcastModel(this, model); }