This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3999bf9
Showing
5 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.gradle | ||
build | ||
jars | ||
out | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
*.txt | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
maven { | ||
name = "forge" | ||
url = "http://files.minecraftforge.net/maven" | ||
} | ||
maven { | ||
name = "sonatype" | ||
url = "https://oss.sonatype.org/content/repositories/snapshots/" | ||
} | ||
} | ||
dependencies { | ||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' | ||
classpath group: 'com.github.rodionmoiseev.gradle.plugins', name: 'idea-utils', version: '0.2' | ||
} | ||
} | ||
|
||
import groovy.json.* | ||
|
||
configurations { | ||
compile | ||
deployJars | ||
} | ||
|
||
apply plugin: "forge" | ||
apply plugin: "maven" | ||
apply plugin: "idea-utils" | ||
|
||
group = "net.doubledoordev.ftsw" | ||
version = "1.1.0" | ||
|
||
targetCompatibility = 1.7 | ||
sourceCompatibility = 1.7 | ||
|
||
archivesBaseName = 'ForgeTwitchSubWhitelist' | ||
def githuborg = 'DoubleDoorDevelopment' | ||
def description = 'Auto checks login attempts against the Twitch API' | ||
minecraft { | ||
version = "1.7.10-10.13.2.1286" | ||
runDir = "jars" | ||
} | ||
|
||
repositories { | ||
maven { | ||
name "DDD repo" | ||
url "http://doubledoordev.net/maven/" | ||
} | ||
} | ||
|
||
dependencies { | ||
compile "net.doubledoordev.d3core:D3Core:" + project.minecraft.version + "-+:dev" | ||
} | ||
|
||
if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER | ||
def builder = new groovy.json.JsonBuilder() | ||
builder (version: version, mcversion: project.minecraft.version, apiversion: project.minecraft.apiVersion) | ||
new File("versions.json").write(builder.toPrettyString()) | ||
|
||
processResources { | ||
from(sourceSets.main.resources.srcDirs) { | ||
include '**/*.info' | ||
expand 'version':project.version, 'mcversion':project.minecraft.version, 'modid':project.archivesBaseName, 'githuborg':githuborg, 'description':description | ||
} | ||
|
||
from(sourceSets.main.resources.srcDirs) { | ||
exclude '**/*.info' | ||
} | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
from "LICENSE.txt" | ||
from sourceSets.main.allSource | ||
classifier = 'src' | ||
appendix = project.minecraft.version | ||
} | ||
|
||
task deobfJar(type: Jar) { | ||
from "LICENSE.txt" | ||
from sourceSets.main.output | ||
from (sourceSets.main.allSource.srcDirs) { | ||
include '**/*.java' | ||
} | ||
classifier = 'dev' | ||
appendix = project.minecraft.version | ||
} | ||
|
||
jar { | ||
from "LICENSE.txt" | ||
appendix = project.minecraft.version | ||
} | ||
|
||
artifacts { | ||
archives jar | ||
archives sourcesJar | ||
archives deobfJar | ||
} | ||
|
||
idea { | ||
project { | ||
copyright { | ||
name = 'New BSD License' | ||
license = file('LICENSE.txt') | ||
} | ||
} | ||
} | ||
|
||
uploadArchives { | ||
if (project.hasProperty("dddUser") && project.hasProperty("dddPass")) { | ||
repositories { | ||
mavenDeployer { | ||
repository(url: "http://doubledoordev.net:8081/artifactory/mods") { | ||
authentication(userName: dddUser, password: dddPass) | ||
} | ||
pom { | ||
groupId = project.group | ||
version = project.minecraft.version + "-" + project.version | ||
artifactId = project.archivesBaseName | ||
project { | ||
name project.archivesBaseName | ||
packaging 'jar' | ||
description = description | ||
url 'https://github.com/' + githuborg + '/' + project.archivesBaseName | ||
|
||
scm { | ||
url 'https://github.com/' + githuborg + '/' + project.archivesBaseName | ||
connection 'scm:git:git://github.com/' + githuborg + '/' + project.archivesBaseName + '.git' | ||
developerConnection 'scm:git:git@github.com:' + githuborg + '/' + project.archivesBaseName + '.git' | ||
} | ||
|
||
issueManagement { | ||
system 'github' | ||
url 'https://github.com/' + githuborg + '/' + project.archivesBaseName + '/issues' | ||
} | ||
|
||
licenses { | ||
license { | ||
name 'New BSD License' | ||
url 'https://raw.github.com/' + githuborg + '/' + project.archivesBaseName + '/master/LICENCE.txt' | ||
distribution 'repo' | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id 'Dries007' | ||
name 'Dries007' | ||
roles { role 'developer' } | ||
} | ||
developer { | ||
id 'Claycorp' | ||
name 'Claycorp' | ||
roles { role 'developer' } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
src/main/java/net/doubledoordev/ftsw/ForgeTwitchSubWhitelist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright (c) 2014, DoubleDoorDevelopment | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the project nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package net.doubledoordev.ftsw; | ||
|
||
import com.google.common.base.Strings; | ||
import cpw.mods.fml.client.config.IConfigElement; | ||
import cpw.mods.fml.common.FMLCommonHandler; | ||
import cpw.mods.fml.common.Mod; | ||
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | ||
import cpw.mods.fml.common.event.FMLServerStartingEvent; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import cpw.mods.fml.common.network.FMLNetworkEvent; | ||
import net.doubledoordev.d3core.util.ID3Mod; | ||
import net.minecraft.network.NetHandlerPlayServer; | ||
import net.minecraft.server.management.ServerConfigurationManager; | ||
import net.minecraftforge.common.config.ConfigElement; | ||
import net.minecraftforge.common.config.Configuration; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Dries007 | ||
*/ | ||
@Mod(modid = ForgeTwitchSubWhitelist.MODID) | ||
public class ForgeTwitchSubWhitelist implements ID3Mod | ||
{ | ||
public static final String MODID = "ForgeTwitchSubWhitelist"; | ||
public static final String CHECK_TWITCH_URL = "http://www.twitch.tv/api/channels/%s/subscriptions/%s?oauth_token=%s"; | ||
public static final String GET_TWITCH_NAME_URL = "http://doubledoordev.net/getTwitchName.php?uuid=%s"; | ||
|
||
@Mod.Instance(MODID) | ||
public static ForgeTwitchSubWhitelist instance; | ||
private Configuration configuration; | ||
|
||
private String twitchToken; | ||
private String channel; | ||
|
||
@Mod.EventHandler | ||
public void init(FMLPreInitializationEvent event) | ||
{ | ||
FMLCommonHandler.instance().bus().register(this); | ||
|
||
configuration = new Configuration(event.getSuggestedConfigurationFile()); | ||
|
||
syncConfig(); | ||
} | ||
|
||
@Mod.EventHandler | ||
public void init(FMLServerStartingEvent event) | ||
{ | ||
event.registerServerCommand(new InfoCommand()); | ||
} | ||
|
||
@SubscribeEvent | ||
public void joinEvent(final FMLNetworkEvent.ServerConnectionFromClientEvent event) | ||
{ | ||
new Thread(new Runnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
if (event.isLocal) return; | ||
ServerConfigurationManager scm = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager(); | ||
scm.setWhiteListEnabled(true); | ||
|
||
NetHandlerPlayServer handler = ((NetHandlerPlayServer) event.handler); | ||
|
||
if (scm.func_152607_e(handler.playerEntity.getGameProfile())) return; // op or whitelisted | ||
|
||
String twitchName; | ||
try | ||
{ | ||
twitchName = IOUtils.toString(new URL(String.format(GET_TWITCH_NAME_URL, handler.playerEntity.getUniqueID().toString()))).trim(); | ||
} | ||
catch (IOException e) | ||
{ | ||
twitchName = handler.playerEntity.getCommandSenderName(); | ||
} | ||
if (Strings.isNullOrEmpty(twitchName)) handler.kickPlayerFromServer("You need to link you MC and Twitch on:\nhttp://www.doubledoordev.net/?p=twitch"); | ||
try | ||
{ | ||
//noinspection ResultOfMethodCallIgnored | ||
IOUtils.toString(new URL(String.format(CHECK_TWITCH_URL, channel, twitchName, twitchToken))); | ||
} | ||
catch (IOException e) | ||
{ | ||
handler.kickPlayerFromServer(String.format("You must be subscribed to %s to join this server.", channel)); | ||
} | ||
|
||
scm.setWhiteListEnabled(false); | ||
} | ||
}).start(); | ||
} | ||
|
||
@Override | ||
public void syncConfig() | ||
{ | ||
configuration.setCategoryLanguageKey(MODID, "d3.forgeTwitchSubWhitelist.config.forgeTwitchSubWhitelist"); | ||
|
||
// public String getString(String name, String category, String defaultValue, String comment) | ||
twitchToken = configuration.getString("twitchToken", MODID, "", "Get it from http://www.doubledoordev.net/?p=twitch"); | ||
channel = configuration.getString("channel", MODID, "", "Cap sensitive!"); | ||
|
||
if (configuration.hasChanged()) configuration.save(); | ||
} | ||
|
||
@Override | ||
public void addConfigElements(List<IConfigElement> configElements) | ||
{ | ||
configElements.add(new ConfigElement(configuration.getCategory(MODID.toLowerCase()))); | ||
} | ||
} |
Oops, something went wrong.