public void ForceChannelSwitch(SockChatUser user, SockChatChannel chan) { if (!Channels.Contains(chan)) { return; } int messageId = SockChatMessage.NextMessageId; SockChatChannel oldChan = user.Channel; oldChan.Send(new UserChannelLeavePacket(user), messageId); chan.Send(new UserChannelJoinPacket(user), messageId); user.Send(new ContextClearPacket(ContextClearMode.MessagesUsers)); user.Send(new ContextUsersPacket(chan.GetUsers(new[] { user }))); IChatMessage[] msgs = GetChannelBacklog(chan); foreach (IChatMessage msg in msgs) { user.Send(new ContextMessagePacket(msg)); } user.ForceChannel(chan); oldChan.UserLeave(user); chan.UserJoin(user); if (oldChan.IsTemporary && oldChan.Owner == user) { DeleteChannel(oldChan); } }
public void HandleJoin(SockChatUser user, SockChatChannel chan, SockChatConn conn) { if (!chan.HasUser(user)) { chan.Send(new UserConnectPacket(DateTimeOffset.Now, user), SockChatMessage.NextMessageId); } conn.Send(new AuthSuccessPacket(user, chan)); conn.Send(new ContextUsersPacket(chan.GetUsers(new[] { user }))); IChatMessage[] msgs = GetChannelBacklog(chan); foreach (IChatMessage msg in msgs) { conn.Send(new ContextMessagePacket(msg)); } lock (Channels) conn.Send(new ContextChannelsPacket(Channels.Where(x => user.Hierarchy >= x.Hierarchy))); if (!chan.HasUser(user)) { chan.UserJoin(user); } if (!Users.Contains(user)) { Users.Add(user); } }
public void SwitchChannel(SockChatUser user, SockChatChannel chan, string password) { if (user.Channel == chan) { //user.Send(true, @"samechan", chan.Name); user.ForceChannel(); return; } if (!user.IsModerator && chan.Owner != user) { if (chan.Hierarchy > user.Hierarchy) { user.Send(true, @"ipchan", chan.Name); user.ForceChannel(); return; } if (chan.Password != password) { user.Send(true, @"ipwchan", chan.Name); user.ForceChannel(); return; } } ForceChannelSwitch(user, chan); }
public EventChatMessage(SockChatChannel chan, string msgId, SockChatMessageFlags flags, bool error, string eventName, params object[] parts) { Channel = chan; MessageIdStr = msgId; Flags = flags; IsError = error; EventName = eventName; Parts = parts; }
public void SwitchChannel(SockChatUser user, string chanName, string password) { SockChatChannel chan = FindChannelByName(chanName); if (chan == null) { user.Send(true, @"nochan", chanName); user.ForceChannel(); return; } SwitchChannel(user, chan, password); }
public void UserLeave(SockChatChannel chan, SockChatUser user, string type = Constants.LEAVE_NORMAL) { if (chan == null) { Channels.Where(x => x.Users.Contains(user)).ToList().ForEach(x => UserLeave(x, user, type)); return; } if (chan.IsTemporary && chan.Owner == user) { DeleteChannel(chan); } chan.UserLeave(user); HandleLeave(chan, user, type); }
public void DeleteChannel(SockChatChannel chan) { if (chan == DefaultChannel) { return; } lock (chan.Users) lock (Users) lock (Channels) { chan.Users.ForEach(u => SwitchChannel(u, DefaultChannel, string.Empty)); Users.Where(u => u.Hierarchy >= chan.Hierarchy).ForEach(u => u.Send(new ChannelDeletePacket(chan))); Channels.Remove(chan); } }
public void UpdateChannel(SockChatChannel chan, string oldName = null) { lock (Users) Users.Where(u => u.Hierarchy >= chan.Hierarchy).ForEach(u => { u.Send(new ChannelUpdatePacket(oldName ?? chan.Name, chan)); /* Not entire sure how to recreate this behaviour at the moment * if ($user->channel == $oldname && $oldname != "") { * $user->runSock(function($sock) use ($channel) { * $sock->send(pack_message(5, ["2", $channel->name])); * }); * $user->channel = $channel->name; * } */ u.ForceChannel(); }); }
public void HandleLeave(SockChatChannel chan, SockChatUser user, string type = Constants.LEAVE_NORMAL) { UserDisconnectReason reason = UserDisconnectReason.Leave; switch (type) { case Constants.LEAVE_TIMEOUT: reason = UserDisconnectReason.TimeOut; break; case Constants.LEAVE_KICK: reason = UserDisconnectReason.Kicked; break; case Constants.LEAVE_FLOOD: reason = UserDisconnectReason.Flood; break; } chan.Send(new UserDisconnectPacket(DateTimeOffset.Now, user, reason)); }
public string AddChannel(SockChatChannel chan) { lock (Channels) { SockChatChannel eChan = FindChannelByName(chan.Name); if (eChan != null) { return(SockChatMessage.PackBotMessage(1, @"nischan", chan.Name)); } if (chan.Name.StartsWith(@"@") || chan.Name.StartsWith(@"*")) { return(SockChatMessage.PackBotMessage(1, @"inchan")); } Channels.Add(chan); lock (Users) Users.Where(u => u.Hierarchy >= chan.Hierarchy).ForEach(u => u.Send(new ChannelCreatePacket(chan))); } return(null); }
public static EventChatMessage Error(SockChatChannel chan, int msgId, SockChatMessageFlags flags, string eventName, params object[] parts) => new EventChatMessage(chan, msgId, flags, true, eventName, parts);
public static EventChatMessage Info(SockChatChannel chan, string msgId, SockChatMessageFlags flags, string eventName, params object[] parts) => new EventChatMessage(chan, msgId, flags, false, eventName, parts);
public static EventChatMessage Info(SockChatChannel chan, int msgId, string eventName, params object[] parts) => new EventChatMessage(chan, msgId, SockChatMessageFlags.RegularUser, false, eventName, parts);
public static EventChatMessage Error(SockChatChannel chan, string msgId, string eventName, params object[] parts) => new EventChatMessage(chan, msgId, SockChatMessageFlags.RegularUser, true, eventName, parts);
public void ForceChannel(SockChatChannel chan = null) => Send(new UserChannelForceJoinPacket(chan ?? Channel));
public IChatMessage[] GetChannelBacklog(SockChatChannel chan, int count = 15) { return(Messages.Where(x => x.Channel == chan || x.Channel == null).Reverse().Take(count).Reverse().ToArray()); }