public bool OnBanUserCommand(IStarProxy proxy, StarCommand command) { if (!proxy.AuthenticatedUser.Admin) return false; ChatReceivedMessage message = new ChatReceivedMessage { Context = new MessageContext { Mode = Mode.CommandResult } }; if (command.Arguments.Length != 2) { message.Text = "Syntax: /banuser <uuid> \"<reason>\" <all characters? (optional)>"; proxy.SendChatMessage(message); } string uuid = command.Arguments[0]; string reason = command.Arguments[1]; string allCharsStr = command.Arguments[1]?.ToLower(); bool allChars = allCharsStr == "yes" || allCharsStr == "true" || allCharsStr == "1"; if (ActivateBanHammer(proxy.Server, uuid, reason, allChars)) message.Text = $"Player with uuid {uuid} has been banned!"; else message.Text = $"Error while trying to ban {uuid}!"; proxy.SendChatMessage(message); return true; }
public bool OnRegisterCommand(IStarProxy proxy, StarCommand command) { var resp = new ChatReceivedMessage { Context = new MessageContext { Mode = Mode.CommandResult } }; if (command.Arguments.Length != 3) { resp.Text = "Syntax: /register <username> <password> <confirm>"; proxy.SendChatMessage(resp); return false; } if (!RegisterUser(command.Arguments[0], command.Arguments[1])) { resp.Text = $"The username {command.Arguments[0]} has already been taken!"; proxy.SendChatMessage(resp); return false; } resp.Text = $"The account {command.Arguments[0]} has been created!"; proxy.SendChatMessage(resp); return true; }
private void OnClientConnect(IStarProxy proxy, IClientConnectPacket packet) { Character ch = _db.Characters.SingleOrDefault(p => p.Uuid == packet.Uuid.Id); bool update = ch != null; if (!update) { ch = new Character(); _db.Characters.Add(ch); } ch.Name = packet.PlayerName; ch.Uuid = packet.Uuid.Id; string ip = ((IPEndPoint)proxy.ClientSocket.RemoteEndPoint).Address.ToString(); CharacterIp chIp = _db.CharacterIps.SingleOrDefault(p => p.Address == ip && p.CharacterId == ch.CharacterId); if (chIp == null) { _db.CharacterIps.Add(new CharacterIp { Character = ch, Address = ip }); } if (update) _db.Update(ch); _db.SaveChanges(); proxy.Character = ch; }
public void OnChatSent(IStarProxy proxy, IChatSentPacket packet) { if (packet.Message.StartsWith("/")) { if (_commandManager.PassCommand(proxy, packet.Message)) packet.Ignore = true; } }
public bool PassCommand(IStarProxy proxy, string command) { StarCommand cmd = StarCommandParser.ParseCommand(command); if (cmd == null) return false; Func<IStarProxy, StarCommand, bool> func = _commands.SingleOrDefault(p => p.Key.Equals(cmd.CommandName, StringComparison.CurrentCultureIgnoreCase)) .Value; return func != null && func(proxy, cmd); }
public void OnClientConnect(IStarProxy proxy, IClientConnectPacket packet) { if (!string.IsNullOrEmpty(packet.Account)) { User user = _db.Users.SingleOrDefault(p => p.Username == packet.Account); if (user != null) { Ban ban = _db.Bans.SingleOrDefault(p => p.UserId == user.UserId); if (ban != null && ban.Active) { IConnectFailurePacket failPacket = _star.Resolve<IConnectFailurePacket>(); failPacket.Reason = ban.Reason; proxy.SendPacket(failPacket, Destination.Client); return; } } _authenticating[proxy] = new AuthenticatingProxy { AccountName = packet.Account, User = user }; packet.Account = string.Empty; proxy.ServerPaused = true; IHandshakeChallengePacket hChallenge = _star.Resolve<IHandshakeChallengePacket>(); if (user != null) hChallenge.PasswordSalt = user.PasswordSalt; else hChallenge.PasswordSalt = StarSecurity.EmptySalt; proxy.SendPacket(hChallenge, Destination.Client); } else { Ban ban = _db.Bans.SingleOrDefault(p => p.Character.Uuid == packet.Uuid.Id); if (ban != null && ban.Active) { IConnectFailurePacket failPacket = _star.Resolve<IConnectFailurePacket>(); failPacket.Reason = ban.Reason; proxy.SendPacket(failPacket, Destination.Client); } } }
public void OnHandshakeChallenge(IStarProxy proxy, IHandshakeChallengePacket packet) { if (_authenticating.ContainsKey(proxy)) { AuthenticatingProxy auth = _authenticating[proxy]; if (auth.User != null) packet.PasswordSalt = auth.User.PasswordSalt; else packet.PasswordSalt = StarSecurity.EmptySalt; } }
public void OnHandshakeResponse(IStarProxy proxy, IHandshakeResponsePacket packet) { if (_authenticating.ContainsKey(proxy)) { packet.Ignore = true; AuthenticatingProxy auth = _authenticating[proxy]; User user = auth.User; Character userChar = proxy.Character; if (user != null && userChar != null && user.PasswordHash.SequenceEqual(packet.PasswordHash)) { proxy.AuthenticatedUser = user; proxy.ServerPaused = false; proxy.FlushPackets(); user.LastLogin = DateTime.UtcNow; userChar.UserId = user.UserId; _db.Update(user); _db.Update(userChar); _db.SaveChanges(); AccountsPlugin.AuthenticatedProxies.AddOrUpdate(proxy, user, (p, u) => user); } else { IConnectFailurePacket failPacket = _star.Resolve<IConnectFailurePacket>(); failPacket.Reason = "Invalid username or password!"; proxy.SendPacket(failPacket, Destination.Client); } while (!_authenticating.TryRemove(proxy, out auth)) Thread.Sleep(1); } }
public PacketEventArgs(IStarProxy proxy, IPacket packet) { Proxy = proxy; Packet = packet; }