void SpawnPlayer(ClientState client) { var sc = ServerSaveLoadController.Instance; var info = sc.GetPlayerInfo(client.UserName); if (info == null) { info = new PlayerEntitySaveInfo { Name = client.UserName, SpawnPoint = DefaultSpawnPoint, HomePoint = DefaultSpawnPoint, LastSavedPos = DefaultSpawnPoint, UsedSkinName = "default" }; sc.UpdatePlayerInfo(info); } var player = new PlayerEntity { Owner = client, PlayerName = client.UserName, Position = info.LastSavedPos, ConId = (ushort)client.ConnectionID }; Players.Add(player); var server = ServerController.Instance; server.SendToAll(ServerPacketID.PlayerSpawn, new S_SpawnPlayerMessage { PlayerToSpawn = player }); EventManager.Fire(new OnServerPlayerSpawn { Player = player, Client = client }); //send all entities ServerDynamicEntityController.Instance.RegisterClient(player, client); }
public void UpdatePlayerInfo(PlayerEntitySaveInfo info) { if (info == null || string.IsNullOrEmpty(info.Name)) { throw new ArgumentNullException("Player info is null or has invalid name"); } var coll = _db.GetCollection <PlayerEntitySaveInfo>("players"); if (!coll.Update(info)) { coll.Insert(info); } coll.EnsureIndex(x => x.Name); }