View Single Post
  #1  
Old 02-23-2010, 05:42 PM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,450
Default COMMITTED: Allow books to be sent in perl

Title says it all, this basically allows books to be sent via perl. Format is $client->ReadBook("text", type)

Type can be 0 or 1, 0 is a scroll, 1 is a book.

Very handy for making a library out of objects in player.pl, in pure example. Use your imagination for this one.

Code:
Index: client.cpp
===================================================================
--- client.cpp	(revision 1262)
+++ client.cpp	(working copy)
@@ -1870,6 +1870,21 @@
 	}
 }
 
+void Client::QuestReadBook(const char* text, int8 type) {
+	string booktxt2 = text;	
+	int length = booktxt2.length();
+	if (booktxt2[0] != '\0') {
+		EQApplicationPacket* outapp = new EQApplicationPacket(OP_ReadBook, length + sizeof(BookText_Struct));
+		BookText_Struct *out = (BookText_Struct *) outapp->pBuffer;
+		out->window = 0xFF;
+		out->type = type;
+		out->invslot = 0;
+		memcpy(out->booktext, booktxt2.c_str(), length);
+		QueuePacket(outapp);
+		safe_delete(outapp);
+	}
+}
+
 void Client::SendClientMoneyUpdate(int8 type,int32 amount){
 	EQApplicationPacket* outapp = new EQApplicationPacket(OP_TradeMoneyUpdate,sizeof(TradeMoneyUpdate_Struct));
 	TradeMoneyUpdate_Struct* mus= (TradeMoneyUpdate_Struct*)outapp->pBuffer;
Index: client.h
===================================================================
--- client.h	(revision 1262)
+++ client.h	(working copy)
@@ -520,6 +520,7 @@
 	void	Stun(int duration);
 	void	UnStun();
 	void	ReadBook(BookRequest_Struct *book);
+	void	QuestReadBook(const char* text, int8 type);
 	void	SendClientMoneyUpdate(int8 type,int32 amount);
 	void	SendMoneyUpdate();
 	bool	TakeMoneyFromPP(uint64 copper);
Index: perl_client.cpp
===================================================================
--- perl_client.cpp	(revision 1262)
+++ perl_client.cpp	(working copy)
@@ -4231,6 +4231,32 @@
 	XSRETURN(1);
 }
 
+XS(XS_Client_ReadBook); /* prototype to pass -Wmissing-prototypes */
+XS(XS_Client_ReadBook)
+{
+	dXSARGS;
+	if (items != 3)
+		Perl_croak(aTHX_ "Usage: Client::ReadBook(THIS, Book Text, Type)");
+	{
+		Client *		THIS;
+		char*			in_txt = (char *)SvPV_nolen(ST(1));
+		int8			type = (int8)SvUV(ST(2));
+		dXSTARG;
+
+		if (sv_derived_from(ST(0), "Client")) {
+			IV tmp = SvIV((SV*)SvRV(ST(0)));
+			THIS = INT2PTR(Client *,tmp);
+		}
+		else
+			Perl_croak(aTHX_ "THIS is not of type Client");
+		if(THIS == NULL)
+			Perl_croak(aTHX_ "THIS is NULL, avoiding crash.");
+
+			THIS->QuestReadBook(in_txt, type);
+	}
+XSRETURN_EMPTY;
+}
+
 #ifdef __cplusplus
 extern "C"
 #endif
@@ -4407,6 +4433,7 @@
 		newXSproto(strcpy(buf, "GetPVPPoints"), XS_Client_GetPVPPoints, file, "$");
 		newXSproto(strcpy(buf, "GetRadiantCrystals"), XS_Client_GetRadiantCrystals, file, "$");
 		newXSproto(strcpy(buf, "GetEbonCrystals"), XS_Client_GetEbonCrystals, file, "$");
+		newXSproto(strcpy(buf, "ReadBook"), XS_Client_ReadBook, file, "$$$");
 	XSRETURN_YES;
 }
Reply With Quote