[C++/Python]Weblink în Chat

Aici poți găsi sisteme complete, verificate și recomandate de echipa 4Metin.
Avatar utilizator
SnaKe
4Metin
4Metin
Mesaje: 24
Membru din: Mie Aug 03, 2022 6:35 pm
Status: Activ
Multumiri primite: 23
Contact:

[C++/Python]Weblink în Chat

Mesaj de SnaKe »

Imagine

P.S: Întotdeauna când umblați într-un fișier .py este recomandată deschiderea cu Notepad++ și configurarea programului astfel:
  • Afișare->Arată simboluri->Afișare spații libere și Tab-uri
  • Codificare->Set de caractere->Central European->Windows
  • În Python va trebui să fiți mereu atent la tab-uri sa nu aveți eventuale erori
Se recomandă instalarea funcției ctrl+v înainte de instalarea acestor funcții care vă permit să accesați link-uri direct din joc.

Deschideți uiChat.py din root și căutați

Cod: Selectaţi tot

		elif chat.CHAT_TYPE_SHOUT == self.GetChatMode():
			self.SetChatMode(chat.CHAT_TYPE_TALKING)
			self.SetText("")

		self.__CheckChatMark()
Adăugați dedesubt

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]
Căutați tot în acest document

Cod: Selectaţi tot

def __SendChatPacket(self, text, type):
și înlocuiți cu (sau ajustați - dacă este cazul/aveți și alte funcții de pe la diferite adaptări/sisteme)

Cod: Selectaţi tot

	def __SendChatPacket(self, text, type):
		if net.IsChatInsultIn(text):
			chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
		else:
			if app.LINK_IN_CHAT:
				link = self.GetLink(text)
				if link != "":
					import chr
					if not chr.IsGameMaster():
						text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
					else:
						text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
Deschideți uiwhisper.py din root și căutați

Cod: Selectaţi tot

def SendWhisper(self):
și înlocuiți cu (sau ajustați - dacă este cazul/aveți și alte funcții de pe la diferite adaptări/sisteme)

Cod: Selectaţi tot

	def SendWhisper(self):
		import time
		text = self.chatLine.GetText()
		textLength = len(text)

		if textLength > 0:
			if app.LINK_IN_CHAT:
				link = self.GetLink(text)
				if link != "":
					import chr
					if not chr.IsGameMaster():
						text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
					else:
						text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")

			if net.IsInsultIn(text):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHAT_INSULT_STRING)
				return
			
			Saat = time.strftime("%H:%M:%S")
			net.SendWhisperPacket(self.targetName, ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "):|cff00ff00|h "  + text)
			self.chatLine.SetText("")

			chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, player.GetName() + ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "): "  + text)
Căutați

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]
și adăugați mai jos

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]

Deschideți interfacemodule.py din root și căutați

Cod: Selectaţi tot

import localeInfo
Adăugați dedesubt

Cod: Selectaţi tot

if app.LINK_IN_CHAT:
	import os
Căutați

Cod: Selectaţi tot

self.wndGuildBuilding = None
Adăugați dedesubt

Cod: Selectaţi tot

		if app.LINK_IN_CHAT:
			self.OpenLinkQuestionDialog = None
Căutați

Cod: Selectaţi tot

self.DRAGON_SOUL_IS_QUALIFIED
Adăugați dedesubt

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def AnswerOpenLink(self, answer):
			if not self.OpenLinkQuestionDialog:
				return

			self.OpenLinkQuestionDialog.Close()
			self.OpenLinkQuestionDialog = None

			if not answer:
				return

			link = constInfo.link
			os.system(link)
Căutați

Cod: Selectaţi tot

def MakeHyperlinkTooltip(self, hyperlink):
Înlocuiți funcția cu

Cod: Selectaţi tot

	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "msg" == type and str(tokens[1]) != player.GetMainCharacterName():
				self.OpenWhisperDialog(str(tokens[1]))				
			elif app.LINK_IN_CHAT and "web" == type and tokens[1].startswith("httpXxX") or "web" == type and tokens[1].startswith("httpsXxX"):
					OpenLinkQuestionDialog = uiCommon.QuestionDialog2()
					OpenLinkQuestionDialog.SetText1(localeInfo.CHAT_OPEN_LINK_DANGER)
					OpenLinkQuestionDialog.SetText2(localeInfo.CHAT_OPEN_LINK)
					OpenLinkQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerOpenLink(arg))
					OpenLinkQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerOpenLink(arg))
					constInfo.link = "start " + tokens[1].replace("XxX", "://").replace("&","^&")
					OpenLinkQuestionDialog.Open()
					self.OpenLinkQuestionDialog = OpenLinkQuestionDialog
			elif app.LINK_IN_CHAT and "sysweb" == type:
				os.system("start " + tokens[1].replace("XxX", "://"))
Deschideți locale_game.txt din client/locale/limba și adăugați

Cod: Selectaţi tot

CHAT_OPEN_LINK_DANGER	Atentie: Acest link poate contine un virus!
CHAT_OPEN_LINK	Doresti sa deschizi acest link ?
Accesați UserInterface/Locale_inc.h.cpp din sursa Binary/client.exe și adaugați

Cod: Selectaţi tot

#define LINK_IN_CHAT
Accesați UserInterface/PythonApplicationModule.h.cpp din sursa Binary/client.exe și adaugați

Cod: Selectaţi tot

#ifdef LINK_IN_CHAT
	PyModule_AddIntConstant(poModule, "LINK_IN_CHAT",	1);
#else
	PyModule_AddIntConstant(poModule, "LINK_IN_CHAT",	0);
#endif
Accesați UserInterface/PythonChatModule.h.cpp din sursa Binary/client.exe

Căutați

Cod: Selectaţi tot

PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
	char * szHyperlink;

	if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
		return Py_BuildException();

	std::string stHyperlink(szHyperlink);
	std::vector<std::string> results;

	split_string(stHyperlink, ":", results, false);

	if (0 == results[0].compare("item"))
	{
		if (results.size() < 6)
			return Py_BuildValue("s", "");

		CItemData * pItemData = NULL;

		if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
		{
			char buf[1024] = { 0 };
			char itemlink[256];
			int len;
			bool isAttr = false;

			len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
					htoi(results[1].c_str()),
					htoi(results[2].c_str()),
					htoi(results[3].c_str()),
					htoi(results[4].c_str()),
					htoi(results[5].c_str()));

			if (results.size() >= 8)
			{
				for (int i = 6; i < results.size(); i += 2)
				{
					len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
							htoi(results[i].c_str()),
							atoi(results[i+1].c_str()));
					isAttr = true;
				}
			}

			if (isAttr)
				snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
			else
				snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());

			return Py_BuildValue("s", buf);
		}
	}

	return Py_BuildValue("s", "");
}
Înlocuiți cu

Cod: Selectaţi tot

PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
	char * szHyperlink;

	if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
		return Py_BuildException();

	std::string stHyperlink(szHyperlink);
	std::vector<std::string> results;

	split_string(stHyperlink, ":", results, false);

	if (0 == results[0].compare("item"))
	{
		if (results.size() < 6)
			return Py_BuildValue("s", "");

		CItemData * pItemData = NULL;

		if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
		{
			char buf[1024] = { 0 };
			char itemlink[256];
			int len;
			bool isAttr = false;

			len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
					htoi(results[1].c_str()),
					htoi(results[2].c_str()),
					htoi(results[3].c_str()),
					htoi(results[4].c_str()),
					htoi(results[5].c_str()));

			if (results.size() >= 8)
			{
				for (int i = 6; i < results.size(); i += 2)
				{
					len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
							htoi(results[i].c_str()),
							atoi(results[i+1].c_str()));
					isAttr = true;
				}
			}

			if (isAttr)
				snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
			else
				snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());

			return Py_BuildValue("s", buf);
		}
	}
#ifdef LINK_IN_CHAT
	else if (0 == results[0].compare("link"))
	{
		char buf[1024] = { 0 };
		snprintf(buf, sizeof(buf), "|cffc9c0f1|H|h%s|h|r", results[1].c_str());
		return Py_BuildValue("s", buf);
	}
#endif

	return Py_BuildValue("s", "");
}
Credite: ZeNu
#Snake 🐍🐍
Avatar utilizator
danielionut
4Metin
4Metin
Mesaje: 16
Membru din: Mar Oct 18, 2022 2:51 pm
Status: Activ
Contact:

Re: [C++/Python]Weblink în Chat

Mesaj de danielionut »

SnaKe scrie: Joi Aug 11, 2022 10:46 am Imagine

P.S: Întotdeauna când umblați într-un fișier .py este recomandată deschiderea cu Notepad++ și configurarea programului astfel:
  • Afișare->Arată simboluri->Afișare spații libere și Tab-uri
  • Codificare->Set de caractere->Central European->Windows
  • În Python va trebui să fiți mereu atent la tab-uri sa nu aveți eventuale erori
Se recomandă instalarea funcției ctrl+v înainte de instalarea acestor funcții care vă permit să accesați link-uri direct din joc.

Deschideți uiChat.py din root și căutați

Cod: Selectaţi tot

		elif chat.CHAT_TYPE_SHOUT == self.GetChatMode():
			self.SetChatMode(chat.CHAT_TYPE_TALKING)
			self.SetText("")

		self.__CheckChatMark()
Adăugați dedesubt

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]
Căutați tot în acest document

Cod: Selectaţi tot

def __SendChatPacket(self, text, type):
și înlocuiți cu (sau ajustați - dacă este cazul/aveți și alte funcții de pe la diferite adaptări/sisteme)

Cod: Selectaţi tot

	def __SendChatPacket(self, text, type):
		if net.IsChatInsultIn(text):
			chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
		else:
			if app.LINK_IN_CHAT:
				link = self.GetLink(text)
				if link != "":
					import chr
					if not chr.IsGameMaster():
						text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
					else:
						text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
Deschideți uiwhisper.py din root și căutați

Cod: Selectaţi tot

def SendWhisper(self):
și înlocuiți cu (sau ajustați - dacă este cazul/aveți și alte funcții de pe la diferite adaptări/sisteme)

Cod: Selectaţi tot

	def SendWhisper(self):
		import time
		text = self.chatLine.GetText()
		textLength = len(text)

		if textLength > 0:
			if app.LINK_IN_CHAT:
				link = self.GetLink(text)
				if link != "":
					import chr
					if not chr.IsGameMaster():
						text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
					else:
						text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")

			if net.IsInsultIn(text):
				chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHAT_INSULT_STRING)
				return
			
			Saat = time.strftime("%H:%M:%S")
			net.SendWhisperPacket(self.targetName, ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "):|cff00ff00|h "  + text)
			self.chatLine.SetText("")

			chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, player.GetName() + ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "): "  + text)
Căutați

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]
și adăugați mai jos

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def GetLink(self, text):
			link = ""
			start = text.find("http://")
			if start == -1:
				start = text.find("https://")
			if start == -1:
				return ""

			return text[start:len(text)].split(" ")[0]

Deschideți interfacemodule.py din root și căutați

Cod: Selectaţi tot

import localeInfo
Adăugați dedesubt

Cod: Selectaţi tot

if app.LINK_IN_CHAT:
	import os
Căutați

Cod: Selectaţi tot

self.wndGuildBuilding = None
Adăugați dedesubt

Cod: Selectaţi tot

		if app.LINK_IN_CHAT:
			self.OpenLinkQuestionDialog = None
Căutați

Cod: Selectaţi tot

self.DRAGON_SOUL_IS_QUALIFIED
Adăugați dedesubt

Cod: Selectaţi tot

	if app.LINK_IN_CHAT:
		def AnswerOpenLink(self, answer):
			if not self.OpenLinkQuestionDialog:
				return

			self.OpenLinkQuestionDialog.Close()
			self.OpenLinkQuestionDialog = None

			if not answer:
				return

			link = constInfo.link
			os.system(link)
Căutați

Cod: Selectaţi tot

def MakeHyperlinkTooltip(self, hyperlink):
Înlocuiți funcția cu

Cod: Selectaţi tot

	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "msg" == type and str(tokens[1]) != player.GetMainCharacterName():
				self.OpenWhisperDialog(str(tokens[1]))				
			elif app.LINK_IN_CHAT and "web" == type and tokens[1].startswith("httpXxX") or "web" == type and tokens[1].startswith("httpsXxX"):
					OpenLinkQuestionDialog = uiCommon.QuestionDialog2()
					OpenLinkQuestionDialog.SetText1(localeInfo.CHAT_OPEN_LINK_DANGER)
					OpenLinkQuestionDialog.SetText2(localeInfo.CHAT_OPEN_LINK)
					OpenLinkQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerOpenLink(arg))
					OpenLinkQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerOpenLink(arg))
					constInfo.link = "start " + tokens[1].replace("XxX", "://").replace("&","^&")
					OpenLinkQuestionDialog.Open()
					self.OpenLinkQuestionDialog = OpenLinkQuestionDialog
			elif app.LINK_IN_CHAT and "sysweb" == type:
				os.system("start " + tokens[1].replace("XxX", "://"))
Deschideți locale_game.txt din client/locale/limba și adăugați

Cod: Selectaţi tot

CHAT_OPEN_LINK_DANGER	Atentie: Acest link poate contine un virus!
CHAT_OPEN_LINK	Doresti sa deschizi acest link ?
Accesați UserInterface/Locale_inc.h.cpp din sursa Binary/client.exe și adaugați

Cod: Selectaţi tot

#define LINK_IN_CHAT
Accesați UserInterface/PythonApplicationModule.h.cpp din sursa Binary/client.exe și adaugați

Cod: Selectaţi tot

#ifdef LINK_IN_CHAT
	PyModule_AddIntConstant(poModule, "LINK_IN_CHAT",	1);
#else
	PyModule_AddIntConstant(poModule, "LINK_IN_CHAT",	0);
#endif
Accesați UserInterface/PythonChatModule.h.cpp din sursa Binary/client.exe

Căutați

Cod: Selectaţi tot

PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
	char * szHyperlink;

	if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
		return Py_BuildException();

	std::string stHyperlink(szHyperlink);
	std::vector<std::string> results;

	split_string(stHyperlink, ":", results, false);

	if (0 == results[0].compare("item"))
	{
		if (results.size() < 6)
			return Py_BuildValue("s", "");

		CItemData * pItemData = NULL;

		if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
		{
			char buf[1024] = { 0 };
			char itemlink[256];
			int len;
			bool isAttr = false;

			len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
					htoi(results[1].c_str()),
					htoi(results[2].c_str()),
					htoi(results[3].c_str()),
					htoi(results[4].c_str()),
					htoi(results[5].c_str()));

			if (results.size() >= 8)
			{
				for (int i = 6; i < results.size(); i += 2)
				{
					len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
							htoi(results[i].c_str()),
							atoi(results[i+1].c_str()));
					isAttr = true;
				}
			}

			if (isAttr)
				snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
			else
				snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());

			return Py_BuildValue("s", buf);
		}
	}

	return Py_BuildValue("s", "");
}
Înlocuiți cu

Cod: Selectaţi tot

PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
	char * szHyperlink;

	if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
		return Py_BuildException();

	std::string stHyperlink(szHyperlink);
	std::vector<std::string> results;

	split_string(stHyperlink, ":", results, false);

	if (0 == results[0].compare("item"))
	{
		if (results.size() < 6)
			return Py_BuildValue("s", "");

		CItemData * pItemData = NULL;

		if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
		{
			char buf[1024] = { 0 };
			char itemlink[256];
			int len;
			bool isAttr = false;

			len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
					htoi(results[1].c_str()),
					htoi(results[2].c_str()),
					htoi(results[3].c_str()),
					htoi(results[4].c_str()),
					htoi(results[5].c_str()));

			if (results.size() >= 8)
			{
				for (int i = 6; i < results.size(); i += 2)
				{
					len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
							htoi(results[i].c_str()),
							atoi(results[i+1].c_str()));
					isAttr = true;
				}
			}

			if (isAttr)
				snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
			else
				snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());

			return Py_BuildValue("s", buf);
		}
	}
#ifdef LINK_IN_CHAT
	else if (0 == results[0].compare("link"))
	{
		char buf[1024] = { 0 };
		snprintf(buf, sizeof(buf), "|cffc9c0f1|H|h%s|h|r", results[1].c_str());
		return Py_BuildValue("s", buf);
	}
#endif

	return Py_BuildValue("s", "");
}
Credite: ZeNu

am bagat tot ca aici fara nici o erroare syserr dar nu mai merge chatul deloc
Avatar utilizator
F. Gabriel
Administrator
Administrator
Mesaje: 507
Membru din: Lun Aug 01, 2022 10:23 am
Localitate: Tecuci
Status: Retras
Multumiri acordate: 18
Multumiri primite: 350
Contact:

Re: [C++/Python]Weblink în Chat

Mesaj de F. Gabriel »

Verifica partea de python.
Imagine

Hosting Metin2 by OVINETWORK.RO
M2FORUM este una dintre cele mai active comunități dedicate jocului Metin2 din România, unde dezvoltatorii și pasionații de servere private pot găsi informații, suport și resurse utile pentru proiectele lor.
Avatar utilizator
danielionut
4Metin
4Metin
Mesaje: 16
Membru din: Mar Oct 18, 2022 2:51 pm
Status: Activ
Contact:

Re: [C++/Python]Weblink în Chat

Mesaj de danielionut »

F. Gabriel scrie: Joi Noi 03, 2022 8:15 am Verifica partea de python.
Da era chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
la mine trebuia acel locale. localeinfo.
Scrie răspuns