Jump to content

Recommended Posts

Posted

So I was bored and I decide to do something to share it.

 

I'll explain a little:

 

So Basically the player talks to a NPC and he writes a msg with whatever he/she wants to report and this its gonna be sended to the administrator mail, so you can see whatever the report on your smartphone or on your pc or w/e.

 

also you need to put a valid gmail account in order to make this work, it doesnt work with yahoo or any of those, just with gmail you can read that in the code, so read it carefuly while you adding it.

 

You can extend it,its the very basic idea.

 

Created: Today.

Credits: Me

 

Thanks to vampir who help me to test the code.

 

### Eclipse Workspace Patch 1.0
#P L2J_Server
Index: java/com/l2jserver/gameserver/model/actor/instance/L2MailReportInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2MailReportInstance.java	(revision 0)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2MailReportInstance.java	(revision 0)
@@ -0,0 +1,138 @@
+package com.l2jserver.gameserver.model.actor.instance;
+
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import com.l2jserver.gameserver.instancemanager.InstanceManager;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+import javolution.text.TextBuilder;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
+
+/**
+ * version v1.1
+ * @author  Mhoska
+ */
+
+public class L2MailReportInstance extends L2NpcInstance {
+
+	public L2MailReportInstance(int objectId, L2NpcTemplate template) {
+		super(objectId, template);
+	}
+
+	@Override
+	public void showChatWindow(L2PcInstance player , int val){
+		if (player == null)
+			return;
+		
+		TextBuilder tb = new TextBuilder();
+		NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
+
+		tb.append("<html><head><title>Reporter For MxC </title></head><body>");
+		tb.append("<center>Welcome " + player.getName() + "</center><br>");
+		tb.append("<center>This is not a toy If you use this and you arent</center><br>");
+		tb.append("<center>really sure of what you re doing</center><br>");
+		tb.append("<center>you could get punished</center><br>");
+		tb.append("<center></center><br>");
+		tb.append("<center></center><br>");
+		tb.append("<center>Now Please do your report.</center><br>");
+		tb.append("Report:<edit var=\"mes\" width=150 height=45><br><br>");
+		tb.append("<button value=\"Send Report\" action=\"bypass -h MailReport $mes\" width=204 height=20>");
+		tb.append("</body></html>");
+
+		html.setHtml(tb.toString());
+		player.sendPacket(html);
+	}
+	
+	@Override
+	@SuppressWarnings("null")
+	public void onBypassFeedback(L2PcInstance player, String command)
+	{
+		if (!canInteract(player))
+			return;
+		if (command.startsWith("MailReport")) {					
+			Long resendtime = InstanceManager.getInstance().getInstanceTime(player.getObjectId(), 99999);
+			   if (System.currentTimeMillis() < resendtime)
+			   {
+				   player.sendMessage("You did a report not too long ago, you gotta wait 24 hours");
+			   }
+				 else{
+			String value = command.substring(6);
+			StringTokenizer s = new StringTokenizer(value, " ");
+			String message = "";
+
+			try {
+				while (s.hasMoreTokens())
+					message = message + s.nextToken() + " ";
+
+				if (message == "" || message == null) {
+					player.sendMessage("Dont try to send a blank message.");
+					return;
+				}
+				if (message.length() < 30) {
+					player.sendMessage("You Must write at leas 30 characters.");
+					return;
+				}
+				if (message.length() > 1000) {
+					player.sendMessage("Maximun 1000 Characters, if you report isn't completed.");
+					player.sendMessage("please send us a new one.");
+					return;
+				}
+
+				try {
+					//Please use a Gmail email because this smtp is coded based on Gmail
+					//just add your real email data or this isn't going to work.
+					//you can set the string to. to any email adress you want to receive the reports.
+					String MyEmail = "trololo@gmail.com";
+					String MyPw = "trololo";
+					String to = "dum-beep-email@gmail.com";
+
+					Properties props = new Properties();
+					props.put("mail.smtps.host", "smtp.gmail.com");
+					props.put("mail.smtps.auth", "true");
+					props.put("mail.transport.protocol", "smtp");
+					props.put("mail.debug", "false");
+
+					Session mailSession = Session.getDefaultInstance(props);
+					Transport transport = mailSession.getTransport("smtps");
+
+					InternetAddress fromAddress = new InternetAddress(MyEmail);
+					InternetAddress toAddress = new InternetAddress(to);
+
+					Message simpleMessage = new MimeMessage(mailSession);
+
+					simpleMessage.setFrom(fromAddress);
+					simpleMessage.setRecipient(Message.RecipientType.TO,
+							toAddress);
+					simpleMessage.setSubject("Ingame Report from:"
+							+ player.getName());
+					simpleMessage.setText("The player Report is:" + message);
+
+					transport.connect("smtp.gmail.com", MyEmail, MyPw);
+					transport.sendMessage(simpleMessage,
+							new Address[] { toAddress });
+					transport.close();
+					
+					InstanceManager.getInstance().setInstanceTime(player.getObjectId(), 99999, ((System.currentTimeMillis() + 86400000)));
+					
+				} catch (Exception e) {
+					System.exit(1);
+				}
+
+			} catch (Exception e) {
+				player.sendMessage("Something gone wrong you gotta do your report again");
+				e.printStackTrace();
+			}
+		}
+		super.onBypassFeedback(player, command);
+	}
+  }
+}
\ No newline at end of file

 

v1.1 update

 

I added a delay on the use of the report, 24 hours.

Posted

[Hidden post: You need 2 karma to see it. You currently have 0.]

It will be very good if make only with topic...

Sorry for spam, but i think its very usefull code.

u have got 1 karma so u cant see it, dont spam the topic.

Posted

Nice spam! :)

I don't think that it is spam by the time he can normally see the post.

 

Anyway, your share is simple but really usefull. Great.

Posted

wut? I just encourage you to keep sharing things with us here in mxc. Is that so bad?

 

2 words :( i hate 2 words post, but np i got the point of your post. and thank you :)

 

Amazing good idea ,some ppl working and they cant stay always in pc to see all the message from players. Good Dude .

 

tyvm :)

I don't think that it is spam by the time he can normally see the post.

 

Anyway, your share is simple but really usefull. Great.

 

thanks for your kind words sir :)

Guest Elfocrash
Posted

Mhoska also mention that this will cuz terrible lag for the server if people do not rework the code working on a separate mailserver

Posted

Mhoska also mention that this will cuz terrible lag for the server if people do not rework the code working on a separate mailserver

 

oh yeah, it may cause lag.

 

but as i say its a pretty basic idea pussaaaay! haha

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...