Minor patch for chatroom chat

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
iamanoob
Plain Yogurt
Plain Yogurt
Posts: 82
Joined: 04 Apr 2008, 09:49

Minor patch for chatroom chat

#1 Post by iamanoob »

outside a chatroom wrote:iamanoob : hahahah
inside a chatroom wrote:iamanoob : hahahah
they are just the same, and we might say something in public if we are not aware if we are in a chatroom or not
(i.e. iamanoob : my momma for your zenny here)

src/Globals.pm

Code: Select all

interface => [qw($interface)],
- misc    => [qw($quit $reconnectCount @lastpm %lastpm @privMsgUsers %timeout_ex $shopstarted $dmgpsec $totalelasped   $elasped $totaldmg %overallAuth %responseVars %talk $startTime_EXP $startingZenny @monsters_Killed $bExpSwitch $jExpSwitch $totalBaseExp $totalJobExp $shopEarned %itemChange $XKore_dontRedirect $monkilltime $monstarttime $startedattack $firstLoginMap $sentWelcomeMessage $versionSearch $monsterBaseExp $monsterJobExp %descriptions %flags %damageTaken $logAppend @sellList $userSeed $taskManager)],
+ misc    => [qw($quit $reconnectCount @lastpm %lastpm @privMsgUsers %timeout_ex $shopstarted $dmgpsec $totalelasped $elasped $totaldmg %overallAuth %responseVars %talk $startTime_EXP $startingZenny @monsters_Killed $bExpSwitch $jExpSwitch $totalBaseExp $totalJobExp $shopEarned %itemChange $XKore_dontRedirect $monkilltime $monstarttime $startedattack $firstLoginMap $sentWelcomeMessage $versionSearch $monsterBaseExp $monsterJobExp %descriptions %flags %damageTaken $logAppend @sellList $userSeed $taskManager $pub)],
Add a line in src/Globals.pm with

Code: Select all

our $taskManager;
+ our $pub;
src/Network/Receive.pm

Code: Select all

sub chat_created {
	my ($self, $args) = @_;

	$currentChatRoom = $accountID;
	$chatRooms{$accountID} = {%createdChatRoom};
	binAdd(\@chatRoomsID, $accountID);
	binAdd(\@currentChatRoomUsers, $char->{name});
	message T("Chat Room Created\n");
+	$pub = 1;
}

Code: Select all

sub chat_newowner {
	my ($self, $args) = @_;

	my $user = bytesToString($args->{user});
	if ($args->{type} == 0) {
		if ($user eq $char->{name}) {
			$chatRooms{$currentChatRoom}{ownerID} = $accountID;
		} else {
			my $players = $playersList->getItems();
			my $player;
			foreach my $p (@{$players}) {
				if ($p->{name} eq $user) {
					$player = $p;
					last;
				}
			}

			if ($player) {
				my $key = $player->{ID};
				$chatRooms{$currentChatRoom}{ownerID} = $key;
			}
		}
		$chatRooms{$currentChatRoom}{users}{$user} = 2;
	} else {
		$chatRooms{$currentChatRoom}{users}{$user} = 1;
	}
-      message T("Chat Room Properties Modified\n");
+	message T("Chat Room Properties Modified [new owner]\n");
}

Code: Select all

sub chat_user_leave {
	my ($self, $args) = @_;

	my $user = bytesToString($args->{user});
	delete $chatRooms{$currentChatRoom}{users}{$user};
	binRemove(\@currentChatRoomUsers, $user);
	$chatRooms{$currentChatRoom}{num_users} = $args->{num_users};
	if ($user eq $char->{name}) {
		binRemove(\@chatRoomsID, $currentChatRoom);
		delete $chatRooms{$currentChatRoom};
		undef @currentChatRoomUsers;
		$currentChatRoom = "";
		message T("You left the Chat Room\n");
+     $pub = 0;
	} else {
		message TF("%s has left the Chat Room\n", $user);
	}
}

Code: Select all

sub chat_users {
	my ($self, $args) = @_;

	my $newmsg;
	$self->decrypt(\$newmsg, substr($args->{RAW_MSG}, 8));
	my $msg = substr($args->{RAW_MSG}, 0, 8).$newmsg;

	my $ID = substr($args->{RAW_MSG},4,4);
	$currentChatRoom = $ID;

	my $chat = $chatRooms{$currentChatRoom} ||= {};

	$chat->{num_users} = 0;
	for (my $i = 8; $i < $args->{RAW_MSG_SIZE}; $i += 28) {
		my $type = unpack("C1",substr($msg,$i,1));
		my ($chatUser) = unpack("Z*", substr($msg,$i + 4,24));
		$chatUser = bytesToString($chatUser);

		if ($chat->{users}{$chatUser} eq "") {
			binAdd(\@currentChatRoomUsers, $chatUser);
			if ($type == 0) {
				$chat->{users}{$chatUser} = 2;
			} else {
				$chat->{users}{$chatUser} = 1;
			}
			$chat->{num_users}++;
		}
	}

	message TF("You have joined the Chat Room %s\n", $chat->{title});
+     $pub = 1;
}

Code: Select all

sub public_chat {
	my ($self, $args) = @_;
	# Type: String
	my $message = bytesToString($args->{message});
	my ($chatMsgUser, $chatMsg); # Type: String
	my ($actor, $dist);

	if ($message =~ /:/) {
		($chatMsgUser, $chatMsg) = split /:/, $message, 2;
		$chatMsgUser =~ s/ $//;
		$chatMsg =~ s/^ //;
		stripLanguageCode(\$chatMsg);

		$actor = Actor::get($args->{ID});
		$dist = "unknown";
		if (!$actor->isa('Actor::Unknown')) {
			$dist = distance($char->{pos_to}, $actor->{pos_to});
			$dist = sprintf("%.1f", $dist) if ($dist =~ /\./);
		}
		$message = "$chatMsgUser ($actor->{binID}): $chatMsg";

	} else {
		$chatMsg = $message;
	}

	my $position = sprintf("[%s %d, %d]",
		$field ? $field->name() : T("Unknown field,"),
		$char->{pos_to}{x}, $char->{pos_to}{y});
	my $distInfo;
	if ($actor) {
		$position .= sprintf(" [%d, %d] [dist=%s] (%d)",
			$actor->{pos_to}{x}, $actor->{pos_to}{y},
			$dist, $actor->{nameID});
		$distInfo = "[dist=$dist] ";
	}

	# this code autovivifies $actor->{pos_to} but it doesnt matter
	chatLog("c", "$position $message\n") if ($config{logChat});
-       message TF("%s%s\n", $distInfo, $message), "publicchat";
+	message TF("%s%s\n", $pub ? '[Pub] ' : $distInfo, $message), "publicchat";

Code: Select all

sub self_chat {
	my ($self, $args) = @_;
	my ($message, $chatMsgUser, $chatMsg); # Type: String

	$message = bytesToString($args->{message});

	($chatMsgUser, $chatMsg) = $message =~ /([\s\S]*?) : ([\s\S]*)/;
	# Note: $chatMsgUser/Msg may be undefined. This is the case on
	# eAthena servers: it uses this packet for non-chat server messages.

	if (defined $chatMsgUser) {
		stripLanguageCode(\$chatMsg);
	} else {
	Plugins::callHook('packet_sysChat', {
		msg => $message
		});
		$message = $message;
	}

	chatLog("c", "$message\n") if ($config{'logChat'});
-      message "$message\n", "selfchat";
+	message TF("%s$message\n",$pub ? '[Pub] ' : ''), "selfchat";

	Plugins::callHook('packet_selfChat', {
		user => $chatMsgUser,
		msg => $chatMsg
	});
}
might add these also...

Code: Select all

sub map_loaded {
	# Note: ServerType0 overrides this function
	my ($self, $args) = @_;
	
+  $pub = 0;
	undef $conState_tries;
	$char = $chars[$config{char}];
	$syncMapSync = pack('V1', $args->{syncMapSync});
i dont know where to add it (whether in map_change or in map_changed) this is for servers with @warp or if you have been gm summoned XD.. unless there's a feature that when you teleport.. you still have your pub on with you XD
so it would be....
outside a chatroom wrote:iamanoob : S> AW 5b
inside a chatroom wrote:[Pub] iamanoob : S> AW 5m
Last edited by iamanoob on 24 May 2009, 23:27, edited 1 time in total.
Image
DARKest Ninja

Technology
Super Moderators
Super Moderators
Posts: 801
Joined: 06 May 2008, 12:47
Noob?: No

Re: Minor patch for chatroom chat

#2 Post by Technology »

Hey iamanoob,
its good that you noticed this and have a solution.
Though having to change and compare old/new code like this is not a good practice.
Could you possibly provide a diff?
That would make it easier for people to quickly check what exactly has changed and thus to review the code.
One ST0 to rule them all? One PE viewer to find them!
One ST_kRO to bring them all and in the darkness bind them...

Mount Doom awaits us, fellowship of OpenKore!

KeithRafael
Human
Human
Posts: 23
Joined: 27 Aug 2009, 04:10
Noob?: No

Re: Minor patch for chatroom chat

#3 Post by KeithRafael »

Hey iamanoob,

is $pub = 0; determines how many user in the chat?

User avatar
help_us
Testers Team
Testers Team
Posts: 106
Joined: 04 Apr 2008, 21:53
Noob?: No
Location: Asia
Contact:

Re: Minor patch for chatroom chat

#4 Post by help_us »

Code: Select all

Index: Globals.pm
===================================================================
--- Globals.pm	(revision 6906)
+++ Globals.pm	(working copy)
@@ -31,7 +31,7 @@
 	state   => [qw($accountID $cardMergeIndex @cardMergeItemsID $charID @chars @chars_old %cart @friendsID %friends %incomingFriend %field $field %homunculus $itemsList @itemsID %items $monstersList @monstersID %monsters @npcsID %npcs $npcsList @playersID %players @portalsID @portalsID_old %portals %portals_old $portalsList @storeList $currentChatRoom @currentChatRoomUsers @chatRoomsID %createdChatRoom %chatRooms @skillsID %storage @storageID @arrowCraftID %guild %incomingGuild @spellsID %spells @unknownPlayers @unknownNPCs $statChanged $skillChanged $useArrowCraft %currentDeal %incomingDeal %outgoingDeal @identifyID @partyUsersID %incomingParty @petsID %pets @venderItemList $venderID @venderListsID @articles $articles %venderLists %monsters_old @monstersID_old %npcs_old %items_old %players_old @playersID_old @servers $sessionID $sessionID2 $accountSex $accountSex2 $map_ip $map_port $KoreStartTime $secureLoginKey $initSync $lastConfChangeTime $petsList $playersList $portalsList @playerNameCacheIDs %playerNameCache %pet $pvp @cashList $slavesList @slavesID %slaves)],
 	network => [qw($remote_socket $net $messageSender $charServer $conState $conState_tries $encryptVal $ipc $bus $lastPacketTime $masterServer $lastswitch $packetParser $bytesSent $bytesReceived $incomingMessages $outgoingClientMessages $enc_val1 $enc_val2)],
 	interface => [qw($interface)],
-	misc    => [qw($quit $reconnectCount @lastpm %lastpm @privMsgUsers %timeout_ex $shopstarted $dmgpsec $totalelasped $elasped $totaldmg %overallAuth %responseVars %talk $startTime_EXP $startingzeny @monsters_Killed $bExpSwitch $jExpSwitch $totalBaseExp $totalJobExp $shopEarned %itemChange $XKore_dontRedirect $monkilltime $monstarttime $startedattack $firstLoginMap $sentWelcomeMessage $versionSearch $monsterBaseExp $monsterJobExp %descriptions %flags %damageTaken $logAppend @sellList $userSeed $taskManager $repairList $mailList $auctionList $questList $hotkeyList $devotionList $cookingList)],
+	misc    => [qw($quit $reconnectCount @lastpm %lastpm @privMsgUsers %timeout_ex $shopstarted $dmgpsec $totalelasped $elasped $totaldmg %overallAuth %responseVars %talk $startTime_EXP $startingzeny @monsters_Killed $bExpSwitch $jExpSwitch $totalBaseExp $totalJobExp $shopEarned %itemChange $XKore_dontRedirect $monkilltime $monstarttime $startedattack $firstLoginMap $sentWelcomeMessage $versionSearch $monsterBaseExp $monsterJobExp %descriptions %flags %damageTaken $logAppend @sellList $userSeed $taskManager $pub $repairList $mailList $auctionList $questList $hotkeyList $devotionList $cookingList)],
 	syncs => [qw($syncSync $syncMapSync)],
 	cmdqueue => [qw($cmdQueue @cmdQueueList $cmdQueueStartTime $cmdQueueTime @cmdQueuePriority)],
 );
@@ -465,6 +465,7 @@
 our @sellList;
 our $userSeed;
 our $taskManager;
+our $pub;
 
 our $bytesSent = 0;
 our $bytesReceived = 0;
Index: Network/Receive/kRO/Sakexe_0.pm
===================================================================
--- Network/Receive/kRO/Sakexe_0.pm	(revision 6906)
+++ Network/Receive/kRO/Sakexe_0.pm	(working copy)
@@ -2082,6 +2082,7 @@
 	binAdd(\@chatRoomsID, $accountID);
 	binAdd(\@currentChatRoomUsers, $char->{name});
 	message T("Chat Room Created\n");
+	$pub = 1;
 }
 
 sub chat_info {
@@ -2164,6 +2165,7 @@
 	} else {
 		$chatRooms{$currentChatRoom}{users}{$user} = 1;
 	}
+	message T("Chat Room Properties Modified [new owner]\n");
 }
 
 sub chat_user_join {
@@ -2191,6 +2193,7 @@
 		undef @currentChatRoomUsers;
 		$currentChatRoom = "";
 		message T("You left the Chat Room\n");
+		$pub = 0;
 	} else {
 		message TF("%s has left the Chat Room\n", $user);
 	}
@@ -2226,6 +2229,7 @@
 	}
 
 	message TF("You have joined the Chat Room %s\n", $chat->{title});
+	$pub = 1;
 }
 
 sub cast_cancelled {
@@ -3976,6 +3980,7 @@
 	# Note: ServerType0 overrides this function
 	my ($self, $args) = @_;
 
+	$pub = 0;
 	undef $conState_tries;
 	$char = $chars[$config{char}];
 	$syncMapSync = pack('V1', $args->{syncMapSync});
@@ -4750,7 +4755,7 @@
 
 	# this code autovivifies $actor->{pos_to} but it doesnt matter
 	chatLog("c", "$position $message\n") if ($config{logChat});
-	message TF("%s%s\n", $distInfo, $message), "publicchat";
+	message TF("%s%s\n", $pub ? '[Pub] ' : $distInfo, $message), "publicchat";
 
 	ChatQueue::add('c', $args->{ID}, $chatMsgUser, $chatMsg);
 	Plugins::callHook('packet_pubMsg', {
@@ -5067,7 +5072,7 @@
 	}
 
 	chatLog("c", "$message\n") if ($config{'logChat'});
-	message "$message\n", "selfchat";
+	message TF("%s$message\n",$pub ? '[Pub] ' : ''), "selfchat";
 
 	Plugins::callHook('packet_selfChat', {
 		user => $chatMsgUser,
Index: Network/Receive/ServerType0.pm
===================================================================
--- Network/Receive/ServerType0.pm	(revision 6906)
+++ Network/Receive/ServerType0.pm	(working copy)
@@ -2003,6 +2003,7 @@
 	binAdd(\@chatRoomsID, $accountID);
 	binAdd(\@currentChatRoomUsers, $char->{name});
 	message T("Chat Room Created\n");
+	$pub = 1;
 }
 
 sub chat_info {
@@ -2085,6 +2086,7 @@
 	} else {
 		$chatRooms{$currentChatRoom}{users}{$user} = 1;
 	}
+	message T("Chat Room Properties Modified [new owner]\n");
 }
 
 sub chat_user_join {
@@ -2112,6 +2114,7 @@
 		undef @currentChatRoomUsers;
 		$currentChatRoom = "";
 		message T("You left the Chat Room\n");
+		$pub = 0;
 	} else {
 		message TF("%s has left the Chat Room\n", $user);
 	}
@@ -2147,6 +2150,7 @@
 	}
 
 	message TF("You have joined the Chat Room %s\n", $chat->{title});
+	$pub = 1;
 }
 
 sub cast_cancelled {
@@ -3897,6 +3901,7 @@
 	# Note: ServerType0 overrides this function
 	my ($self, $args) = @_;
 
+	$pub = 0;
 	undef $conState_tries;
 	$char = $chars[$config{char}];
 	$syncMapSync = pack('V1', $args->{syncMapSync});
@@ -4671,7 +4676,7 @@
 
 	# this code autovivifies $actor->{pos_to} but it doesnt matter
 	chatLog("c", "$position $message\n") if ($config{logChat});
-	message TF("%s%s\n", $distInfo, $message), "publicchat";
+	message TF("%s%s\n", $pub ? '[Pub] ' : $distInfo, $message), "publicchat";
 
 	ChatQueue::add('c', $args->{ID}, $chatMsgUser, $chatMsg);
 	Plugins::callHook('packet_pubMsg', {
@@ -4988,7 +4993,7 @@
 	}
 
 	chatLog("c", "$message\n") if ($config{'logChat'});
-	message "$message\n", "selfchat";
+	message TF("%s$message\n",$pub ? '[Pub] ' : ''), "selfchat";
 
 	Plugins::callHook('packet_selfChat', {
 		user => $chatMsgUser,
test it and it work ;)
thank you iamanoob
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Image
Image

Post Reply