Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Prevent Anti-AutoSign & Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Sep 28, 2016
1 parent 3308605 commit a7b2346
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 100 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/kamesuta/mc/signpic/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class Client {
public static File mcDir;
public static File signpicDir;
public static File signpicCacheDir;
public static File configDir;
public static File configFile;
public static File modDir;
public static File modFile;

Expand Down
120 changes: 116 additions & 4 deletions src/main/java/com/kamesuta/mc/signpic/Config.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,119 @@
package com.kamesuta.mc.signpic;

// TODO
public class Config {
public Config() {
import java.io.File;

import org.apache.commons.lang3.StringUtils;

import com.kamesuta.mc.signpic.handler.CoreEvent;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

public final class Config extends Configuration {
public static Config instance;

private final File configFile;
public boolean updatable;

public int imageWidthLimit = 512;
public int imageHeightLimit = 512;
public boolean imageAnimationGif = true;

public int entryGCtick = 15;

public int contentLoadThreads = 3;
public int contentMaxByte = 0;
public int contentGCtick = 15 * 20;
public int contentAsyncTick = 0;
public int contentSyncTick = 0;

public boolean informationNotice = true;
public boolean informationJoinBeta = false;

public boolean multiplayPAAS = true;
/** Fastest time "possible" estimate for an empty sign. */
public int multiplayPAASMinEditTime = 150;
/** Minimum time needed to add one extra line (not the first). */
public int multiplayPAASMinLineTime = 50;
/** Minimum time needed to type a character. */
public int multiplayPAASMinCharTime = 50;

public float renderSeeOpacity = .5f;
public float renderPreviewFixedOpacity = .7f;
public float renderPreviewFloatedOpacity = .7f;

public Config( final File configFile ) {
super( configFile );
this.configFile = configFile;

this.imageWidthLimit = get( "Image", "WidthLimit", this.imageWidthLimit ).setRequiresMcRestart(true).getInt( this.imageWidthLimit );
this.imageHeightLimit = get( "Image", "HeightLimit", this.imageHeightLimit ).setRequiresMcRestart(true).getInt( this.imageHeightLimit );
this.imageAnimationGif = get( "Image", "AnimateGif", this.imageAnimationGif ).setRequiresMcRestart(true).getBoolean( this.imageAnimationGif );

addCustomCategoryComment("Entry", "Entry(sign text parse cache) Management");

addCustomCategoryComment("Content", "Content Data Management");

this.informationNotice = get( "Version", "Notice", this.informationNotice ).setRequiresMcRestart(true).getBoolean( this.informationNotice );
this.informationJoinBeta = get( "Version", "JoinBeta", this.informationJoinBeta ).setRequiresMcRestart(true).getBoolean( this.informationJoinBeta );

addCustomCategoryComment("MultiplayPreventAntiAutoSign", "Prevent from Anti-AutoSign Plugin such as NoCheatPlus. (ms)");

changeableSync();

this.updatable = true;
}

private void changeableSync() {
this.entryGCtick = get( "Entry", "GCDelayTick", this.entryGCtick ).getInt( this.entryGCtick );

this.contentLoadThreads = addComment(get( "Content", "LoadThreads", this.contentLoadThreads ), "parallel processing number such as Downloading").setRequiresMcRestart(true).getInt( this.contentLoadThreads );
this.contentMaxByte = addComment(get( "Content", "MaxByte", this.contentMaxByte ), "limit of size before downloading").getInt( this.contentMaxByte );
this.contentGCtick = addComment(get( "Content", "GCDelayTick", this.contentGCtick ), "delay ticks of Garbage Collection").getInt( this.contentGCtick );
this.contentAsyncTick = addComment(get( "Content", "AsyncLoadDelayTick", this.contentAsyncTick ), "ticks of Async process starting delay (Is other threads, it does not disturb the operation) such as Downloading, File Loading...").getInt( this.contentAsyncTick );
this.contentSyncTick = addComment(get( "Content", "SyncLoadIntervalTick", this.contentSyncTick ), "ticks of Sync process interval (A drawing thread, affects the behavior. Please increase the value if the operation is heavy.) such as Gl Texture Uploading").getInt( this.contentSyncTick );

this.multiplayPAAS = get( "MultiplayPreventAntiAutoSign", "Enable", this.multiplayPAAS ).getBoolean( this.multiplayPAAS );
this.multiplayPAASMinEditTime = get( "MultiplayPreventAntiAutoSign", "minEditTime", this.multiplayPAASMinEditTime ).getInt( this.multiplayPAASMinEditTime );
this.multiplayPAASMinLineTime = get( "MultiplayPreventAntiAutoSign", "minLineTime", this.multiplayPAASMinLineTime ).getInt( this.multiplayPAASMinLineTime );
this.multiplayPAASMinCharTime = get( "MultiplayPreventAntiAutoSign", "minCharTime", this.multiplayPAASMinCharTime ).getInt( this.multiplayPAASMinCharTime );

this.renderSeeOpacity = (float) get( "Render", "ViewSignOpacity", this.renderSeeOpacity ).getDouble( this.renderSeeOpacity );
this.renderPreviewFixedOpacity = (float) get( "Render", "PreviewFixedSignOpacity", this.renderPreviewFixedOpacity ).getDouble( this.renderPreviewFixedOpacity );
this.renderPreviewFloatedOpacity = (float) get( "Render", "PreviewFloatedSignOpacity", this.renderPreviewFloatedOpacity ).getDouble( this.renderPreviewFloatedOpacity );
}

private Property addComment(final Property prop, final String comment) {
prop.comment = comment;
return prop;
}

@Override
public void save()
{
if( hasChanged() )
{
super.save();
}
}

@CoreEvent
public void onConfigChanged( final ConfigChangedEvent.OnConfigChangedEvent eventArgs )
{
if( StringUtils.equals(eventArgs.modID, Reference.MODID) )
{
changeableSync();

if( this.updatable )
{
save();
}
}
}

public String getFilePath()
{
return this.configFile.getPath();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/com/kamesuta/mc/signpic/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Reference {
public static final String MINECRAFT = "${mcversion}";
public static final String PROXY_SERVER = "com.kamesuta.mc.signpic.proxy.CommonProxy";
public static final String PROXY_CLIENT = "com.kamesuta.mc.signpic.proxy.ClientProxy";
public static final String GUI_FACTORY = "com.kamesuta.mc.signpic.gui.config.ConfigGuiFactory";

public static Logger logger = LogManager.getLogger(Reference.MODID);
}
4 changes: 3 additions & 1 deletion src/main/java/com/kamesuta/mc/signpic/SignPicture.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY)
public class SignPicture {
@Instance(Reference.MODID)
public static SignPicture instance;
Expand All @@ -29,6 +29,7 @@ public boolean checkModList(final Map<String, String> versions, final Side side)

@EventHandler
public void preInit(final FMLPreInitializationEvent event) {
Config.instance = new Config(event.getSuggestedConfigurationFile());
proxy.preInit(event);
}

Expand All @@ -40,5 +41,6 @@ public void init(final FMLInitializationEvent event) {
@EventHandler
public void postInit(final FMLPostInitializationEvent event) {
proxy.postInit(event);
Config.instance.save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.google.common.collect.Maps;
import com.kamesuta.mc.signpic.handler.CoreEvent;

public class EntryManager implements ITickEntry {
public static final EntryManager instance = new EntryManager();

public final ExecutorService threadpool = Executors.newFixedThreadPool(3);
private final Map<EntryId, EntrySlot<Entry>> registry = Maps.newHashMap();

public Entry get(final EntryId id) {
protected Entry get(final EntryId id) {
final EntrySlot<Entry> entries = this.registry.get(id);
if (entries!=null)
return entries.get();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/kamesuta/mc/signpic/entry/EntrySlot.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.kamesuta.mc.signpic.entry;

import com.kamesuta.mc.signpic.Config;

public class EntrySlot<T> {
public static final int CollectTimes = 20 * 15;
protected static long times = 0;

protected final T entry;
Expand All @@ -23,10 +24,14 @@ public EntrySlot<T> used() {
}

public boolean shouldCollect() {
return times - this.time > CollectTimes;
return times - this.time > getCollectTimes();
}

public static void Tick() {
times++;
}

protected int getCollectTimes() {
return Config.instance.entryGCtick;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kamesuta.mc.signpic.entry.content;

import java.io.IOException;

public class ContentCapacityOverException extends IOException {
public ContentCapacityOverException() {
}

public ContentCapacityOverException(final String message) {
super(message);
}

public ContentCapacityOverException(final Throwable cause) {
super(cause);
}

public ContentCapacityOverException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;

import com.kamesuta.mc.signpic.Config;
import com.kamesuta.mc.signpic.entry.IAsyncProcessable;
import com.kamesuta.mc.signpic.util.Downloader;

Expand All @@ -38,6 +39,11 @@ public void onAsyncProcess() throws URISyntaxException, IllegalStateException, I
final HttpResponse response = Downloader.downloader.client.execute(req);
final HttpEntity entity = response.getEntity();

final long max = Config.instance.contentMaxByte;
final long size = entity.getContentLength();
if (max > 0 && (size < 0 || size > max))
throw new ContentCapacityOverException();

this.content.state.progress.overall = entity.getContentLength();
input = entity.getContent();
countoutput = new CountingOutputStream(new BufferedOutputStream(new FileOutputStream(local))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.kamesuta.mc.signpic.Config;
import com.kamesuta.mc.signpic.entry.IAsyncProcessable;
import com.kamesuta.mc.signpic.entry.IDivisionProcessable;
import com.kamesuta.mc.signpic.entry.ITickEntry;
Expand All @@ -16,15 +17,17 @@
public class ContentManager implements ITickEntry {
public static ContentManager instance = new ContentManager();

public final ExecutorService threadpool = Executors.newFixedThreadPool(3);
public final ExecutorService threadpool = Executors.newFixedThreadPool(Config.instance.contentLoadThreads);
protected final HashMap<ContentId, ContentSlot<Content>> registry = new HashMap<ContentId, ContentSlot<Content>>();
public Deque<IAsyncProcessable> asyncqueue = new ArrayDeque<IAsyncProcessable>();
public Deque<IDivisionProcessable> divisionqueue = new ArrayDeque<IDivisionProcessable>();
private int asynctick = 0;
private int divisiontick = 0;

public ContentManager() {
private ContentManager() {
}

public Content get(final ContentId id) {
protected Content get(final ContentId id) {
final ContentSlot<Content> entries = this.registry.get(id);
if (entries!=null)
return entries.get();
Expand All @@ -38,28 +41,36 @@ public Content get(final ContentId id) {
@CoreEvent
@Override
public void onTick() {
IAsyncProcessable asyncprocess;
if ((asyncprocess = this.asyncqueue.poll()) != null) {
final IAsyncProcessable asyncprocessexec = asyncprocess;
this.threadpool.execute(new Runnable() {
@Override
public void run() {
try {
asyncprocessexec.onAsyncProcess();
} catch (final Exception e) {
e.printStackTrace();
this.asynctick++;
if (this.asynctick > Config.instance.contentAsyncTick) {
this.asynctick = 0;
IAsyncProcessable asyncprocess;
if ((asyncprocess = this.asyncqueue.poll()) != null) {
final IAsyncProcessable asyncprocessexec = asyncprocess;
this.threadpool.execute(new Runnable() {
@Override
public void run() {
try {
asyncprocessexec.onAsyncProcess();
} catch (final Exception e) {
e.printStackTrace();
}
}
}
});
});
}
}
IDivisionProcessable divisionprocess;
if ((divisionprocess = this.divisionqueue.peek()) != null) {
try {
if (divisionprocess.onDivisionProcess()) {
this.divisionqueue.poll();
this.divisiontick++;
if (this.divisiontick > Config.instance.contentAsyncTick) {
this.divisiontick = 0;
IDivisionProcessable divisionprocess;
if ((divisionprocess = this.divisionqueue.peek()) != null) {
try {
if (divisionprocess.onDivisionProcess()) {
this.divisionqueue.poll();
}
} catch (final Exception e) {
e.printStackTrace();
}
} catch (final Exception e) {
e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.kamesuta.mc.signpic.entry.content;

import com.kamesuta.mc.signpic.Config;
import com.kamesuta.mc.signpic.entry.EntrySlot;
import com.kamesuta.mc.signpic.entry.ICollectable;
import com.kamesuta.mc.signpic.entry.IInitable;

public class ContentSlot<T extends IInitable & ICollectable> extends EntrySlot<T> implements IInitable, ICollectable {
public static int CollectTimes = 20 * 15;
public static long times = 0;

private boolean init = true;

public ContentSlot(final T entry) {
Expand All @@ -28,4 +26,9 @@ public boolean shouldInit() {
public void onCollect() {
this.entry.onCollect();
}

@Override
protected int getCollectTimes() {
return Config.instance.contentGCtick;
}
}
Loading

0 comments on commit a7b2346

Please sign in to comment.