public bool Command(ThePalaceEntities dbContext, UInt32 UserID, UInt32 TargetID, params string[] args) { var sessionState = UserID != 0xFFFFFFFF ? SessionManager.sessionStates[UserID] : null; var roomID = (args.Length > 0 ? args[0].TryParse <Int16>() : null) ?? sessionState?.RoomID ?? 0; if (roomID > 0) { var roomUsers = SessionManager.sessionStates.Values .Where(s => s.RoomID == roomID) .ToList(); var room = dbContext.GetRoom(roomID); if (!room.NotFound) { room.Delete(dbContext); } var sendBusinesses = new List <ISendBusiness> { new MSG_ROOMDESC(), new MSG_USERLIST(), new MSG_ROOMDESCEND(), }; var userNew = new MSG_USERNEW(); foreach (var roomUser in roomUsers) { roomID = dbContext.FindRoomID(0, roomUser.Authorized); room = dbContext.GetRoom(roomID); if (!room.NotFound) { roomUser.RoomID = room.ID; foreach (var sendBusiness in sendBusinesses) { sendBusiness.Send(dbContext, new Message { sessionState = roomUser, }); } userNew.SendToRoomID(dbContext, new Message { sessionState = roomUser, }); } } Logger.Log(MessageTypes.Info, $"CMD_DELETEROOM[{sessionState?.AuthUserID ?? -1}]: {room.Name}"); } return(true); }
public void Send(ThePalaceEntities dbContext, object message) { var sessionState = ((Message)message).sessionState; var roomID = dbContext.FindRoomID(sessionState.reg.desiredRoom); if (roomID == 0) { new MSG_SERVERDOWN { reason = ServerDownFlags.SD_ServerFull, whyMessage = "The Server is full!", }.Send(dbContext, message); sessionState.driver.DropConnection(); return; } sessionState.RoomID = roomID; sessionState.successfullyConnected = true; var sendBusinesses = new List <ISendBusiness> { new MSG_ALTLOGONREPLY(), new MSG_VERSION(), new MSG_SERVERINFO(), new MSG_USERSTATUS(), }; foreach (var sendBusiness in sendBusinesses) { sendBusiness.Send(dbContext, message); } new MSG_USERLOG().SendToServer(dbContext, message); using (var dbContextTransaction = dbContext.Database.BeginTransaction()) { try { dbContext.Users1.Add(new Users1 { UserId = (Int32)sessionState.UserID, Name = sessionState.reg.userName, RoomId = sessionState.RoomID, Flags = sessionState.userFlags, }); dbContext.UserData.Add(new UserData { UserId = (Int32)sessionState.UserID, RoomPosH = sessionState.details.roomPos.h, RoomPosV = sessionState.details.roomPos.v, FaceNbr = sessionState.details.faceNbr, ColorNbr = sessionState.details.colorNbr, AwayFlag = 0, OpenToMsgs = 0, }); dbContext.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); ex.DebugLog(); } } new MSG_HTTPSERVER().Send(dbContext, message); new MSG_ROOMGOTO().Receive(dbContext, new Message { sessionState = sessionState, protocol = new Protocols.MSG_ROOMGOTO { dest = sessionState.RoomID, }, }); }