/// <summary> /// Accepts a buddy request and notifies the sender (if online) and the receiver. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object of the user that accepts the request.</param> /// <param name="senderID">The database ID of the user that sent the request.</param> public void acceptBuddyRequest(ref Session Session, int senderID) { Database Database = new Database(false, false); Database.addParameterWithValue("userid", Session.User.ID); Database.addParameterWithValue("senderid", senderID); Database.Open(); if (Database.findsResult("SELECT userid FROM messenger_buddylist WHERE userid = @senderid AND buddyid = @userid AND accepted = '0' LIMIT 1")) { Database.runQuery("UPDATE messenger_buddylist SET accepted = '1' WHERE userid = @senderid AND buddyid = @userid LIMIT 1"); Database.Close(); serverMessage Message = new serverMessage(); if (ObjectTree.Game.Users.userIsLoggedIn(senderID)) // Sender is online! { Message.Initialize(137); // "BI" Message.Append(getBuddy(Session.User.ID).ToString()); ObjectTree.Game.Users.trySendGameMessage(senderID, Message); } Message.Initialize(137); // "BI" Message.Append(getBuddy(senderID).ToString()); Session.gameConnection.sendMessage(Message); } else Database.Close(); }
/// <summary> /// Constructs a roomUser object for a given session. /// </summary> /// <param name="mySession">The Woodpecker.Sessions.Session object of the session where this room user belongs to.</param> public roomUser(Session mySession) { this.Session = mySession; }
/// <summary> /// Generates the trade box for a given session and returns it as as string. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object to generate the trade box string for.</param> public string generateTradeBox(Session Session) { fuseStringBuilder Box = new fuseStringBuilder(); if (Session.itemStripHandler.isTrading) { Box.appendTabbedValue(Session.User.Username); Box.appendTabbedValue(Session.itemStripHandler.tradeAccept.ToString().ToLower()); Box.Append(Session.itemStripHandler.getTradeOfferItems()); Box.appendChar(13); } return Box.ToString(); }
/// <summary> /// Initializes a new game connection instance. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object for this connection.</param> /// <param name="gameClient">The System.Net.Sockets.Socket object of the game client that has been accepted by the game connection listener.</param> public gameConnection(Session Session, Socket gameClient) { this.Session = Session; this.Socket = gameClient; }
/// <summary> /// Creates a session for a user, assigning the session ID and adding it to the collection of sessions. Afterwards, the normal game packet routine is started. /// </summary> /// <param name="gameClient">The System.Net.Sockets.Socket object of the game client that has been accepted by the game connection listener.</param> public void createSession(Socket gameClient) { uint sessionID = this.sessionCounter++; Session Session = new Session(sessionID, gameClient); this._Sessions.Add(sessionID, Session); Logging.Log("Created session " + sessionID + " for " + Session.ipAddress, Logging.logType.sessionConnectionEvent); Session.Start(); }
/// <summary> /// Sets the Woodpecker.Sessions.Session object for this reactor. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session to set.</param> public void setSession(Session Session) { this.Session = Session; }
/// <summary> /// Adds a Woodpecker.Sessions.Session object to the collection of user sessions, with the user ID as key. /// </summary> /// <param name="userSession">The Woodpecker.Sessions.Session to add.</param> public void addUserSession(Session userSession) { if (!_userSessions.ContainsKey(userSession.User.ID)) _userSessions.Add(userSession.User.ID, userSession); }
/// <summary> /// Registers a new user by writing the given details into the 'users' table of the database. /// </summary> /// <param name="Session"></param> /// <param name="Info">The information about the new user in a userInformation object.</param> public void registerUser(Session Session, userInformation Info) { Database Database = new Database(false, true); Database.addParameterWithValue("username", Info.Username); Database.addParameterWithValue("password", Info.Password); Database.addParameterWithValue("role", "1"); Database.addParameterWithValue("figure", Info.Figure); Database.addParameterWithValue("sex", Info.Sex.ToString()); Database.addParameterWithValue("motto", Configuration.getConfigurationValue("users.registration.motto")); Database.addParameterWithValue("motto_messenger", Configuration.getConfigurationValue("users.registration.messengermotto")); Database.addParameterWithValue("credits", Configuration.getNumericConfigurationValue("users.registration.credits")); Database.addParameterWithValue("tickets", Configuration.getNumericConfigurationValue("users.registration.tickets")); Database.addParameterWithValue("film", 0); Database.addParameterWithValue("email", Info.Email); Database.addParameterWithValue("dob", Info.DateOfBirth); Database.Open(); if (Database.Ready) { //Database.runQuery("CALL register_user(@username,@password,@figure,@sex,@email,@dob,@receivemails)"); Database.runQuery( "INSERT INTO users " + "(username,password,role,signedup,figure,sex,motto,motto_messenger,credits,tickets,film,lastactivity,club_lastupdate,email,dob) " + "VALUES " + "(@username,@password,@role,NOW(),@figure,@sex,@motto,@motto_messenger,@credits,@tickets,@film,NOW(),NOW(),@email,@dob)"); Logging.Log("Created user '" + Info.Username + "'.", Logging.logType.userVisitEvent); } else Logging.Log("Failed to create user " + Info.Username + ", because the database was not contactable!", Logging.logType.commonWarning); }
/// <summary> /// Gets the transactions (credit log) of a user on given user session and sends it to the session's game connection. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object to get the transaction for and to send the message to.</param> public void sendTransactions(ref Session Session) { if (Session.User == null) return; serverMessage Message = new serverMessage(209); // "CQ" Database Database = new Database(false, true); Database.addParameterWithValue("userid", Session.User.ID); Database.Open(); if (Database.Ready) { DataTable creditLogData = Database.getTable("SELECT moment,type,activity FROM users_creditlog WHERE userid = @userid LIMIT 50"); foreach (DataRow dRow in creditLogData.Rows) { DateTime Moment = (DateTime)dRow["moment"]; Message.appendTabbedValue(Moment.ToString("dd/MM/yyyy")); Message.appendTabbedValue(Moment.ToString("hh:mm")); Message.appendTabbedValue(dRow["activity"].ToString()); Message.appendTabbedValue("0"); Message.appendTabbedValue(""); Message.Append(dRow["type"].ToString()); Message.appendChar(13); } } Session.gameConnection.sendMessage(Message); }
/// <summary> /// Tries to redeem a credit/item voucher for a user session. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object to redeem the voucher with.</param> /// <param name="Code">The vouchercode the user entered.</param> public void redeemVoucher(ref Session Session, string Code) { serverMessage Response = new serverMessage(); Database Database = new Database(false, false); Database.addParameterWithValue("code", Code); Database.Open(); if (Database.Ready) { DataRow dRow = Database.getRow("SELECT type,value FROM users_vouchers WHERE code = @code AND ISNULL(redeemer_userid)"); if (dRow != null) // Voucher found { // Mark voucher as redeemed Database.addParameterWithValue("userid", Session.User.ID); Database.runQuery("UPDATE users_vouchers SET redeemer_userid = @userid WHERE code = @code"); Database.Close(); string Type = (string)dRow["type"]; if (Type == "credits") { int Credits = int.Parse(dRow["value"].ToString()); Session.User.Credits += Credits; Session.User.updateValueables(); this.logTransaction(Session.User.ID, "win_voucher", Credits); Session.refreshCredits(); } else if (Type == "item") { string[] Items = ((string)dRow["value"]).Split(';'); } // Success! Response.Initialize(212); // "CT" Session.gameConnection.sendMessage(Response); return; } else { // Error 1! (not found) Response.Initialize(213); // "CU" Response.Append(1); } Session.gameConnection.sendMessage(Response); } }
public bool purchaseSubscription(ref Session Session, string Subscription, int Choice) { if (Subscription != "club_habbo") return false; int Cost = 0; int Months = 0; if (Choice == 1) { Cost = 25; Months = 1; } else if (Choice == 2) { Cost = 60; Months = 3; } else if (Choice == 3) { Cost = 105; Months = 6; } else return false; if (Cost > Session.User.Credits) return false; else { for (int i = 1; i <= Months; i++) { if (Session.User.clubDaysLeft == 0) Session.User.clubDaysLeft = 31; else Session.User.clubMonthsLeft++; } this.logTransaction(Session.User.ID, "club_habbo", -Cost); Session.User.Credits -= Cost; Session.User.updateValueables(); Session.User.updateClub(true); return true; } }
public reactorHandler(Session Session) { this.Session = Session; }
/// <summary> /// Activates a room user and makes it appear in the door of the room. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object of the user that is ready to interact with the room.</param> public void startUser(Session Session) { if (!enteringSessions.Contains(Session.ID)) // Invalid entry return; roomUser newUser = new roomUser(Session); if (Session.authenticatedTeleporter == 0) { roomModel Model = this.getModel(); newUser.X = Model.doorX; newUser.Y = Model.doorY; newUser.Z = Model.doorZ; } else { Items.floorItem pItem = this.getFloorItem(Session.authenticatedTeleporter); if(pItem != null && pItem.Definition.Behaviour.isTeleporter) { newUser.X = pItem.X; newUser.Y = pItem.Y; newUser.Z = pItem.Z; Session.authenticatedTeleporter = 0; this.broadcoastTeleportActivity(pItem.ID, Session.User.Username, false); } else return; // Invalid item used to enter flat } newUser.ID = this.getFreeRoomUnitIdentifier(); if (this.Information.isUserFlat) { newUser.isOwner = (Session.User.Username == this.Information.Owner || Session.User.hasFuseRight("fuse_any_room_controller")); newUser.hasRights = (newUser.isOwner || this.Information.superUsers || ObjectTree.Game.Rooms.userHasRightsInRoom(Session.User.ID, this.roomID)); newUser.refreshRights(); } // User has entered Session.roomID = this.roomID; this.enteringSessions.Remove(Session.ID); this.roomUsers.Add(Session.ID, newUser); this.castRoomUnit(newUser.ToString()); this.updateUserAmount(); }