Jump to content

Recommended Posts

Posted

Hi there!

 

This is my first post, so please bare with my (or my skills... or understanding of "everything").

 

I searched for a good while on this forums before registering, but I was not able to find the information I need. As you can conclude from the title, I want a server-side only mod. From other threads in this forums I recap, that I need to have Forge installed on the clients. But what is actually not clear to me is, that I definitively need my mod on the client's side, even if it does not add any blocks or something.

 

First of all, what am I planning to do?

I want to write a mod, that hooks events like logging in and out, getting an achievement, player dies, kills a mob etc and sends a web request to a certain website. Actually, I want to create a battle log.

 

Which problem arises?

I developed my plugin within Eclipse so far, hitting the green play button several times. It worked flawlessly, except the logout event. I found out, that this is only caught server-side, so I opted for a server-side plugin.

I compiled a .jar file and threw it into my server's mods folder. It got loaded (referring to the log), but when I tried to connect to the server with my 1.7.10-Forge client, the login got rejected with the message "mods rejected: [FMLMod:webhookmod{1.0}]".

 

What is the correct approach to solve this error? The @NetworkMod annotation is gone, so is the @SideOnly. Do I have to have stubbed functions for the client? Is it enough to have the Listener registered without having any listening methods in it? How do I get the executing environment (Client/Server)?

In short: What is the correct approach? ;)

Find my code attached at the bottom.

 

The actual API calls should only be fired server-side, because players could argue, that sending an additional HTTP request may have produced some lag on their side (while sending it from the server, all players would be affected equally).

 

Small update

I stumbled upon Proxies. I guess this is what I need to implement. By having my Client overwriting the Server class, it seems that this solves my problem. :) Thanks for the views ;)

 

package de.barooney.minecraft.webhook;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;

import cpw.mods.fml.common.*;
import cpw.mods.fml.common.Mod.*;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.eventhandler.*;
import cpw.mods.fml.common.gameevent.PlayerEvent;

/**
* 
* @author barooney
* 
* Mod to send in-game events to a specified URL 
*
*/

@Mod(modid = WebhookMod.MODID, name = WebhookMod.NAME, version = WebhookMod.VERSION)
public class WebhookMod
{
public static final String MODID = "webhookmod";
public static final String NAME = "Webhook API Mod";
public static final String VERSION = "1.0";
public static final String acceptedMinecraftVersions = "";

public WebhookMod() {
	String targetURL = "http://localhost:8080/wp-content/plugins/minecraft-api/api.php";
	String sessionId = new BigInteger(130, new SecureRandom()).toString(32);
	System.out.println("Created new Webhandler with Session ID " + sessionId);
}

// register events for fml only, because there are no events watched, that would require ModForge.EVENT_BUS
@EventHandler
public void init(FMLInitializationEvent event)
{ 
	FMLCommonHandler.instance().bus().register(new WebhookMod());
}

// Player logs in
@SubscribeEvent
public void playerLogIn(PlayerEvent.PlayerLoggedInEvent event)
{
	System.out.println(event.player.getDisplayName());
	System.out.println("Sending self_join event to webhook...");
}

// Player logs out - not fired client-side 
@SubscribeEvent
public void playerLogOut(PlayerEvent.PlayerLoggedOutEvent event)
{
	System.out.println(event.player.getDisplayName());
	System.out.println("Sending self_left event to webhook...");
}
}

Posted

If you want to allow clients to connect without the mod installed, add

acceptableRemoteVersions = "*"

to your @Mod.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.