« blib/lib/auto/share/dist/Games-Axmud/plugins/mxpfilter.pm
↑ Summary
blib/lib/Games/Axmud/Profile.pm »
| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # General Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Games::Axmud::Obj::MiniWorld | ||
| 16 | # A mini-world object used by the Connections window to temporarily store changes makde to a world | ||
| 17 | # profile's settings in that window, until they can be stored in the profile itself | ||
| 18 | |||
| 19 | { package Games::Axmud::Obj::MiniWorld; | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | # use diagnostics; | ||
| 24 | |||
| 25 | use Glib qw(TRUE FALSE); | ||
| 26 | |||
| 27 | our @ISA = qw(Games::Axmud); | ||
| 28 | |||
| 29 | ################## | ||
| 30 | # Constructors | ||
| 31 | |||
| 32 | sub new { | ||
| 33 | |||
| 34 | # Called by GA::OtherWin::Connect->resetTreeView, ->resetTableWidgets, | ||
| 35 | # ->createWorldCallback and ->resetWorldCallback | ||
| 36 | # Creates a new instance of the mini-world object - temporarily stores any changes made to a | ||
| 37 | # world profile's data in the Connections window; when the window is closed, the world | ||
| 38 | # profiles themselves can be updated | ||
| 39 | # When the window is displaying the basic mudlist, not a list of world profiles, this | ||
| 40 | # mini-world object stores changes to the basic world object (GA::Obj::BasicWorld), which | ||
| 41 | # are later used to create a new world profile | ||
| 42 | # | ||
| 43 | # Expected arguments | ||
| 44 | # (none besides $self) | ||
| 45 | # | ||
| 46 | # Optional arguments (all set to 'undef' if this is a temporary mini-world that doesn't yet | ||
| 47 | # correspond to an existing world profile) | ||
| 48 | # | ||
| 49 | # $worldObj - The GA::Profile::World object that might be modified by this object's | ||
| 50 | # stored data (can also be a GA::Obj::BasicWorld object, if a world | ||
| 51 | # profile doesn't exist yet) | ||
| 52 | # $selectChar - The world profile's last connected character (->lastConnectChar), which | ||
| 53 | # may be 'undef' | ||
| 54 | # $loginAccountMode | ||
| 55 | # - The world profile's login account mode (->loginAccountMode) | ||
| 56 | # $pwdHashRef - Reference to a hash copied from the profile object's ->passwordHash | ||
| 57 | # $accHashRef - Reference to a hash copied from the profile object's ->accountHash | ||
| 58 | # | ||
| 59 | # Return values | ||
| 60 | # 'undef' on improper arguments or if $name is invalid | ||
| 61 | # Blessed reference to the newly-created object on success | ||
| 62 | |||
| 63 | my ( | ||
| 64 | $class, $worldObj, $selectChar, $loginAccountMode, $pwdHashRef, $accHashRef, $check, | ||
| 65 | ) = @_; | ||
| 66 | |||
| 67 | # Local variables | ||
| 68 | my ( | ||
| 69 | $name, | ||
| 70 | %passwordHash, %accountHash, | ||
| 71 | ); | ||
| 72 | |||
| 73 | # Check for improper arguments | ||
| 74 | if (! defined $class || defined $check) { | ||
| 75 | |||
| 76 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 77 | } | ||
| 78 | |||
| 79 | if (! defined $worldObj) { | ||
| 80 | $name = 'unnamed_mini_world'; | ||
| 81 | } else { | ||
| 82 | $name = $worldObj->name; | ||
| 83 | } | ||
| 84 | |||
| 85 | if (! defined $loginAccountMode) { | ||
| 86 | |||
| 87 | $loginAccountMode = 'unknown'; | ||
| 88 | } | ||
| 89 | |||
| 90 | if (defined $pwdHashRef) { | ||
| 91 | |||
| 92 | %passwordHash = %$pwdHashRef; | ||
| 93 | } | ||
| 94 | |||
| 95 | if (defined $accHashRef) { | ||
| 96 | |||
| 97 | %accountHash = %$accHashRef; | ||
| 98 | } | ||
| 99 | |||
| 100 | # Setup | ||
| 101 | my $self = { | ||
| 102 | _objName => $name, | ||
| 103 | _objClass => $class, | ||
| 104 | _parentFile => undef, # No parent file | ||
| 105 | _parentWorld => undef, # No parent file | ||
| 106 | _privFlag => FALSE, # All IVs are public | ||
| 107 | |||
| 108 | # IVs | ||
| 109 | # --- | ||
| 110 | |||
| 111 | # The GA::Profile::World object (or GA::Obj::BasicWorld) and its ->name | ||
| 112 | name => $name, | ||
| 113 | worldObj => $worldObj, | ||
| 114 | # An IV initially set to the world profile's last connected character (might be set | ||
| 115 | # to 'undef'. When the user selects a character from the table's combobox, this IV is | ||
| 116 | # set to that value (or to 'undef' if the 'no character' item is selected) | ||
| 117 | selectChar => $selectChar, | ||
| 118 | # Login account mode - whether an account name is needed to login to this world, as well | ||
| 119 | # as the usual character name/password. Used only to set the label text in some of | ||
| 120 | # the Connections window's 'dialogue' windows; doesn't affect the automatic login | ||
| 121 | # process | ||
| 122 | loginAccountMode => $loginAccountMode, | ||
| 123 | |||
| 124 | # Hash of IVs, in the form | ||
| 125 | # $propHash{iv_name} = scalar_value | ||
| 126 | # If the user makes any changes to a world in the Connections window, those changes are | ||
| 127 | # stored in this hash. When it's time to update the world profile, | ||
| 128 | # $self->storeChangesCallback copies them into the corresponding world profile object | ||
| 129 | # 'iv_name' can be any of 'name', 'host', 'port' or 'descrip' | ||
| 130 | propHash => {}, | ||
| 131 | # The world profile's ->loginMode IV is not stored here; instead, we store the state of | ||
| 132 | # the 'Auto-login' checkbutton (TRUE or FALSE), and pass the result to | ||
| 133 | # GA::Client->startSession | ||
| 134 | noAutoLoginFlag => undef, | ||
| 135 | # A hash of characters and passwords, in the same form as | ||
| 136 | # GA::Profile::World->passwordHash, i.e. | ||
| 137 | # $passwordHash{char_profile_name} = password | ||
| 138 | # $passwordHash{char_profile_name} = 'undef' (if password not known) | ||
| 139 | passwordHash => \%passwordHash, | ||
| 140 | # ->passwordHash is initially copied from the world profile's ->passwordHash. Any | ||
| 141 | # changes are also stored in this hash. (Changes include adding a new character, | ||
| 142 | # regardless of whether the new character's password is set, or not) | ||
| 143 | newPasswordHash => {}, | ||
| 144 | # A hash of characters and associated account names, in the same form as | ||
| 145 | # GA::Profile::World->accountHash, i.e. | ||
| 146 | # $charHash{char_profile_name} = account | ||
| 147 | # $charHash{char_profile_name} = 'undef' (if no associated account) | ||
| 148 | accountHash => \%accountHash, | ||
| 149 | # ->accountHash is initially copied from the world profile's ->accountHash. Any changes | ||
| 150 | # are also stored in this hash. (Changes include adding a new character, regardless of | ||
| 151 | # whether the new character's password is set, or not) | ||
| 152 | newAccountHash => {}, | ||
| 153 | |||
| 154 | # Flag used in Axmud test mode. When set to TRUE, a world profile's ->numberConnects is | ||
| 155 | # set to at least 1, so that the tester can connect to the world in offline mode, | ||
| 156 | # and the next time the GA::OtherWin::Connect is opened, the world will be visible | ||
| 157 | # near the top of its list | ||
| 158 | testModeFlag => FALSE, | ||
| 159 | }; | ||
| 160 | |||
| 161 | # Bless the object into existence | ||
| 162 | bless $self, $class; | ||
| 163 | return $self; | ||
| 164 | } | ||
| 165 | |||
| 166 | ################## | ||
| 167 | # Methods | ||
| 168 | |||
| 169 | sub reset { | ||
| 170 | |||
| 171 | # Called by GA::OtherWin::Connect->applyChangesCallback | ||
| 172 | # Resets some of this objects IVs after they have been transferred to a world profile | ||
| 173 | # | ||
| 174 | # Expected arguments | ||
| 175 | # (none besides $self) | ||
| 176 | # | ||
| 177 | # Return values | ||
| 178 | # 'undef' on improper arguments | ||
| 179 | # 1 otherwise | ||
| 180 | |||
| 181 | my ($self, $check) = @_; | ||
| 182 | |||
| 183 | # Check for improper arguments | ||
| 184 | if (defined $check) { | ||
| 185 | |||
| 186 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset', @_); | ||
| 187 | } | ||
| 188 | |||
| 189 | # Reset IVs | ||
| 190 | $self->ivEmpty('propHash'); | ||
| 191 | $self->ivEmpty('newPasswordHash'); | ||
| 192 | $self->ivEmpty('newAccountHash'); | ||
| 193 | |||
| 194 | if (! $self->worldObj) { | ||
| 195 | |||
| 196 | $self->ivEmpty('passwordHash'); | ||
| 197 | $self->ivEmpty('accountHash'); | ||
| 198 | } | ||
| 199 | |||
| 200 | return 1; | ||
| 201 | } | ||
| 202 | |||
| 203 | ################## | ||
| 204 | # Accessors - set | ||
| 205 | |||
| 206 | ################## | ||
| 207 | # Accessors - get | ||
| 208 | |||
| 209 | sub name | ||
| 210 | { $_[0]->{name} } | ||
| 211 | sub worldObj | ||
| 212 | { $_[0]->{worldObj} } | ||
| 213 | sub selectChar | ||
| 214 | { $_[0]->{selectChar} } | ||
| 215 | sub loginAccountMode | ||
| 216 | { $_[0]->{loginAccountMode} } | ||
| 217 | |||
| 218 | sub propHash | ||
| 219 | { my $self = shift; return %{$self->{propHash}}; } | ||
| 220 | sub noAutoLoginFlag | ||
| 221 | { $_[0]->{noAutoLoginFlag} } | ||
| 222 | sub passwordHash | ||
| 223 | { my $self = shift; return %{$self->{passwordHash}}; } | ||
| 224 | sub newPasswordHash | ||
| 225 | { my $self = shift; return %{$self->{newPasswordHash}}; } | ||
| 226 | sub accountHash | ||
| 227 | { my $self = shift; return %{$self->{accountHash}}; } | ||
| 228 | sub newAccountHash | ||
| 229 | { my $self = shift; return %{$self->{newAccountHash}}; } | ||
| 230 | |||
| 231 | sub testModeFlag | ||
| 232 | { $_[0]->{testModeFlag} } | ||
| 233 | } | ||
| 234 | |||
| 235 | # Package must return a true value | ||
| 236 | 1 |