|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Threading.Tasks; |
5 | 6 | using System.Web; |
@@ -152,5 +153,98 @@ public ActionResult ChatHistory(ChatHistoryModel model) { |
152 | 153 | return View("LobbyChatHistory", model); |
153 | 154 | } |
154 | 155 |
|
| 156 | + public class ChatModel |
| 157 | + { |
| 158 | + public string Channel { get; set; } |
| 159 | + public string User { get; set; } |
| 160 | + public string Message { get; set; } |
| 161 | + public IQueryable<LobbyChatHistory> Data = new List<LobbyChatHistory>().AsQueryable(); |
| 162 | + } |
| 163 | + |
| 164 | + [Auth] |
| 165 | + public ActionResult ChatNotification(ChatModel model) |
| 166 | + { |
| 167 | + model = model ?? new ChatModel(); |
| 168 | + |
| 169 | + var db = new ZkDataContext(); |
| 170 | + var acc = db.Accounts.Where(x => x.AccountID == Global.AccountID).First(); |
| 171 | + var ret = db.LobbyChatHistories.AsQueryable(); |
| 172 | + ret = ret.Where(x => x.Target == Global.Account.Name && x.SayPlace == SayPlace.User && x.Time > acc.LastChatRead); |
| 173 | + model.Data = ret.OrderByDescending(x => x.Time).ToList().AsQueryable(); |
| 174 | + model.Channel = ""; |
| 175 | + acc.LastChatRead = DateTime.UtcNow; |
| 176 | + db.SaveChanges(); |
| 177 | + |
| 178 | + return PartialView("ChatNotification", model); |
| 179 | + } |
| 180 | + [Auth] |
| 181 | + public async Task<ActionResult> ChatMessages(ChatModel model) |
| 182 | + { |
| 183 | + model = model ?? new ChatModel(); |
| 184 | + |
| 185 | + var db = new ZkDataContext(); |
| 186 | + var ret = db.LobbyChatHistories.AsQueryable(); |
| 187 | + bool isMuted = Punishment.GetActivePunishment(Global.AccountID, Request.UserHostAddress, 0, null, x => x.BanMute) != null; |
| 188 | + if (!string.IsNullOrEmpty(model.Channel)) |
| 189 | + { |
| 190 | + // only show allowed channels |
| 191 | + if (!Global.Server.ChannelManager.CanJoin(Global.Account, model.Channel)) return PartialView("LobbyChatMessages", model); |
| 192 | + if (!String.IsNullOrEmpty(model.Message) && !isMuted) |
| 193 | + { |
| 194 | + await Global.Server.GhostSay(new Say() |
| 195 | + { |
| 196 | + IsEmote = false, |
| 197 | + Place = SayPlace.Channel, |
| 198 | + Ring = false, |
| 199 | + Source = SaySource.Zk, |
| 200 | + Target = model.Channel, |
| 201 | + Text = model.Message, |
| 202 | + Time = DateTime.UtcNow, |
| 203 | + User = Global.Account.Name, |
| 204 | + }); |
| 205 | + } |
| 206 | + ret = ret |
| 207 | + .Where(x => x.Target == model.Channel && x.SayPlace == SayPlace.Channel) |
| 208 | + .OrderByDescending(x => x.Time).Take(200); |
| 209 | + } |
| 210 | + else if (!string.IsNullOrEmpty(model.User)) |
| 211 | + { |
| 212 | + if (!String.IsNullOrEmpty(model.Message) && !isMuted) |
| 213 | + { |
| 214 | + await Global.Server.GhostSay(new Say() |
| 215 | + { |
| 216 | + IsEmote = false, |
| 217 | + Place = SayPlace.User, |
| 218 | + Ring = false, |
| 219 | + Source = SaySource.Zk, |
| 220 | + Target = model.User, |
| 221 | + Text = model.Message, |
| 222 | + Time = DateTime.UtcNow, |
| 223 | + User = Global.Account.Name, |
| 224 | + }); |
| 225 | + } |
| 226 | + //Users can abuse rename to gain access to other users PMs, it's a feature |
| 227 | + ret = ret |
| 228 | + .Where(x => (x.User == model.User && x.Target == Global.Account.Name || x.User == Global.Account.Name && x.Target == model.User) && x.SayPlace == SayPlace.User) |
| 229 | + .OrderByDescending(x => x.Time); |
| 230 | + } |
| 231 | + else |
| 232 | + { |
| 233 | + return PartialView("LobbyChatMessages", model); |
| 234 | + } |
| 235 | + |
| 236 | + model.Data = ret; |
| 237 | + model.Message = ""; |
| 238 | + |
| 239 | + return PartialView("LobbyChatMessages", model); |
| 240 | + } |
| 241 | + [Auth] |
| 242 | + public ActionResult Chat(ChatModel model) |
| 243 | + { |
| 244 | + model = model ?? new ChatModel(); |
| 245 | + |
| 246 | + return View("LobbyChat", model); |
| 247 | + } |
| 248 | + |
155 | 249 | } |
156 | 250 | } |
0 commit comments