« blib/lib/Games/Axmud/Obj/Tts.pm
↑ Summary
blib/lib/auto/share/dist/Games-Axmud/plugins/_mcptest_objs.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::ChatContact | ||
| 16 | # Stores a chat contact | ||
| 17 | |||
| 18 | { package Games::Axmud::Obj::ChatContact; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | # use diagnostics; | ||
| 23 | |||
| 24 | use Glib qw(TRUE FALSE); | ||
| 25 | |||
| 26 | our @ISA = qw(Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Creates a new instance of the chat contact object | ||
| 34 | # | ||
| 35 | # Expected arguments | ||
| 36 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 37 | # $name - A unique string name for this chat contact (max 16 chars, containing | ||
| 38 | # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable. | ||
| 39 | # Must not exist as a key in the global hash of reserved names, | ||
| 40 | # GA::CLIENT->constReservedHash) | ||
| 41 | # $protocol - Which chat protocol to use by default with this contact (currently 0 for | ||
| 42 | # MudMaster, 1 for zChat) | ||
| 43 | # | ||
| 44 | # Optional arguments | ||
| 45 | # $ip - The contact's advertised IP address ('undef' if not advertised) | ||
| 46 | # $port - The contact's advertised port ('undef' if not advertised) | ||
| 47 | # $email - The contact's advertised email ('undef' if none) | ||
| 48 | # | ||
| 49 | # Return values | ||
| 50 | # 'undef' on improper arguments or if $name is invalid | ||
| 51 | # Blessed reference to the newly-created object on success | ||
| 52 | |||
| 53 | my ($class, $session, $name, $protocol, $ip, $port, $email, $check) = @_; | ||
| 54 | |||
| 55 | # Local variables | ||
| 56 | my $path; | ||
| 57 | |||
| 58 | # Check for improper arguments | ||
| 59 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 60 | |||
| 61 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 62 | } | ||
| 63 | |||
| 64 | # Check that $name is valid and not already in use by another chat contact | ||
| 65 | if (! $axmud::CLIENT->nameCheck($name, 16)) { | ||
| 66 | |||
| 67 | return $axmud::CLIENT->writeError( | ||
| 68 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 69 | $class . '->new', | ||
| 70 | ); | ||
| 71 | |||
| 72 | } elsif ($axmud::CLIENT->ivExists('chatContactHash', $name)) { | ||
| 73 | |||
| 74 | return $axmud::CLIENT->writeError( | ||
| 75 | 'Registry naming error: there is already a chat contact called \'' . $name . '\'', | ||
| 76 | $class . '->new', | ||
| 77 | ); | ||
| 78 | } | ||
| 79 | |||
| 80 | # Make sure $protocol is '0' or '1' (which matches a key in GA::Task::Chat->constOptHash) | ||
| 81 | if (! $protocol) { | ||
| 82 | $protocol = 0; # MudMaster protocol | ||
| 83 | } else { | ||
| 84 | $protocol = 1; # zChat protocol | ||
| 85 | } | ||
| 86 | |||
| 87 | # Setup | ||
| 88 | my $self = { | ||
| 89 | _objName => $name, | ||
| 90 | _objClass => $class, | ||
| 91 | _parentFile => 'contacts', | ||
| 92 | _parentWorld => undef, | ||
| 93 | _privFlag => FALSE, # All IVs are public | ||
| 94 | |||
| 95 | # IVs | ||
| 96 | # --- | ||
| 97 | |||
| 98 | # A unique name for the chat contact (hopefully the same one that the contacts | ||
| 99 | # themselves are broadcasting) (max 16 chars, containing A-Za-z0-9_ - 1st char can't | ||
| 100 | # be number, non-Latin alphabets acceptable. Must not exist as a key in the global | ||
| 101 | # hash of reserved names, GA::CLIENT->constReservedHash) | ||
| 102 | name => $name, | ||
| 103 | # Which chat protocol to use by default with this contact (currently 0 for MudMaster, 1 | ||
| 104 | # for zChat) | ||
| 105 | protocol => $protocol, | ||
| 106 | # Contact's advertised IP address ('undef' if not advertised) | ||
| 107 | ip => $ip, | ||
| 108 | # Contact's advertised port ('undef' if not advertised) | ||
| 109 | port => $port, | ||
| 110 | # Contact's advertised email ('undef' if not advertised) | ||
| 111 | email => $email, | ||
| 112 | |||
| 113 | # The last icon send by the contact - set to a Gtk3::Gdk::Pixbuf | ||
| 114 | lastIcon => undef, # Set below | ||
| 115 | # A scaled copy of the last icon (at size 16x16) for use in the 'edit' window's simple | ||
| 116 | # list | ||
| 117 | lastIconScaled => undef, # Set below | ||
| 118 | }; | ||
| 119 | |||
| 120 | # Bless the object into existence | ||
| 121 | bless $self, $class; | ||
| 122 | |||
| 123 | # Create a Gtk3::Gdk::Pixbuf for the icon to be used as the chat contact's default icon | ||
| 124 | $path = $axmud::SHARE_DIR . $axmud::CLIENT->constChatContactIcon; | ||
| 125 | if (-e $path) { | ||
| 126 | |||
| 127 | my $pixBuffer = Gtk3::Gdk::Pixbuf->new_from_file($path); | ||
| 128 | if ($pixBuffer) { | ||
| 129 | |||
| 130 | # Create a scaled copy of this icon | ||
| 131 | my $pixBuffer2 = Gtk3::Gdk::Pixbuf->new_from_file_at_scale($path, 16, 16, 1); | ||
| 132 | if ($pixBuffer2) { | ||
| 133 | |||
| 134 | # Update IVs | ||
| 135 | $self->{lastIcon} = $pixBuffer; | ||
| 136 | $self->{lastIconScaled} = $pixBuffer2; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | return $self; | ||
| 142 | } | ||
| 143 | |||
| 144 | ################## | ||
| 145 | # Methods | ||
| 146 | |||
| 147 | ################## | ||
| 148 | # Accessors - set | ||
| 149 | |||
| 150 | ################## | ||
| 151 | # Accessors - get | ||
| 152 | |||
| 153 | sub name | ||
| 154 | { $_[0]->{name} } | ||
| 155 | sub protocol | ||
| 156 | { $_[0]->{protocol} } | ||
| 157 | sub ip | ||
| 158 | { $_[0]->{ip} } | ||
| 159 | sub port | ||
| 160 | { $_[0]->{port} } | ||
| 161 | sub email | ||
| 162 | { $_[0]->{email} } | ||
| 163 | |||
| 164 | sub lastIcon | ||
| 165 | { $_[0]->{lastIcon} } | ||
| 166 | sub lastIconScaled | ||
| 167 | { $_[0]->{lastIconScaled} } | ||
| 168 | } | ||
| 169 | |||
| 170 | # Package must return a true value | ||
| 171 | 1 |