Work on Customer support server.

This commit is contained in:
Jonathan Williams 2014-08-21 15:55:09 -05:00
parent 1398543490
commit 99d15d3ece
24 changed files with 537 additions and 257 deletions

View File

@ -73,6 +73,37 @@
</jar>
<copy file="../bin/Hub.jar" todir="../../Testing/Hub/plugins"/>
</target>
<target name ="StaffServer" description="StaffServer">
<jar jarfile="../bin/StaffServer.jar">
<fileset dir="../Mineplex.StaffServer/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Core/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Core.Common/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.StaffServer">
<include name="*.yml"/>
</fileset>
<fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/httpclient-4.2.jar" />
<zipfileset src="../Libraries/httpcore-4.2.jar" />
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
<zipfileset src="../Libraries/httpmime-4.2.jar" />
<zipfileset src="../Libraries/gson-2.2.1.jar" />
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
<zipfileset src="../Libraries/commons-io-2.4.jar" />
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
</jar>
<copy file="../bin/StaffServer.jar" todir="../../Testing/StaffServer/plugins"/>
</target>
<target name ="MapParser" description="MapParser">
<jar jarfile="../bin/MapParser.jar">
<fileset dir="../Mineplex.MapParser/bin">

View File

@ -0,0 +1,103 @@
package mineplex.core.common.util;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.*;
public class UUIDFetcher
{
private static UUIDFetcher _instance = new UUIDFetcher();
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser _jsonParser = new JSONParser();
public UUID getPlayerUUID(String name)
{
UUID uuid = null;
List<String> nameList = new ArrayList<String>();
nameList.add(name);
try
{
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(nameList.subList(0, Math.min(100, 1)));
writeBody(connection, body);
JSONArray array = (JSONArray) _jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array)
{
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
uuid = UUIDFetcher.getUUID(id);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
return uuid;
}
private static void writeBody(HttpURLConnection connection, String body) throws Exception
{
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static HttpURLConnection createConnection() throws Exception
{
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
private static UUID getUUID(String id)
{
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-"
+ id.substring(16, 20) + "-" + id.substring(20, 32));
}
public static byte[] toBytes(UUID uuid)
{
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static UUID fromBytes(byte[] array)
{
if (array.length != 16)
{
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
public static UUID getUUIDOf(String name)
{
if (_instance == null)
_instance = new UUIDFetcher();
return _instance.getPlayerUUID(name);
}
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="Arcade,Hub,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="Arcade,Hub,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="Arcade,Hub,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="Arcade,Hub,StaffServer,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="Arcade,Hub,StaffServer,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="Arcade,Hub,StaffServer,"/>
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>

View File

@ -18,6 +18,7 @@ import mineplex.core.account.repository.token.ClientToken;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.logger.Logger;
import mineplex.core.timing.TimingManager;
@ -37,8 +38,6 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.base.Charsets;
public class CoreClientManager extends MiniPlugin
{
private JavaPlugin _plugin;
@ -154,13 +153,24 @@ public class CoreClientManager extends MiniPlugin
public void loadClientByName(final String playerName, final Runnable runnable)
{
final CoreClient client = Add(playerName);
final UUID uuid = UUID.nameUUIDFromBytes((playerName).getBytes(Charsets.UTF_8));
final UUID uuid = UUIDFetcher.getUUIDOf(playerName);
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
LoadClient(client, uuid, "null");
ClientToken token = null;
Gson gson = new Gson();
String response = _repository.getClientByUUID(uuid);
token = gson.fromJson(response, ClientToken.class);
client.SetAccountId(token.AccountId);
client.SetRank(Rank.valueOf(token.Rank));
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response));
Bukkit.getServer().getScheduler().runTask(GetPlugin(), new Runnable()
{
public void run()

View File

@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.List;
import mineplex.core.common.CurrencyType;
import mineplex.core.donation.repository.token.CoinTransactionToken;
import mineplex.core.donation.repository.token.DonorToken;
import mineplex.core.donation.repository.token.TransactionToken;
public class Donor
{
@ -13,6 +15,8 @@ public class Donor
private boolean _donated;
private List<Integer> _salesPackagesOwned;
private List<String> _unknownSalesPackagesOwned;
private List<TransactionToken> _transactions;
private List<CoinTransactionToken> _coinTransactions;
private boolean _update = true;
@ -24,6 +28,9 @@ public class Donor
_salesPackagesOwned = token.SalesPackages;
_unknownSalesPackagesOwned = token.UnknownSalesPackages;
_transactions = token.Transactions;
_coinTransactions = token.CoinRewards;
if (_salesPackagesOwned == null)
{
@ -34,6 +41,11 @@ public class Donor
{
_unknownSalesPackagesOwned = new ArrayList<String>();
}
if (_unknownSalesPackagesOwned == null)
{
_transactions = new ArrayList<TransactionToken>();
}
}
public int GetGems()
@ -118,6 +130,11 @@ public class Donor
_unknownSalesPackagesOwned.add(packageName);
}
public List<TransactionToken> getTransactions()
{
return _transactions;
}
public boolean OwnsUltraPackage()
{
for (String packageName : _unknownSalesPackagesOwned)
@ -138,4 +155,9 @@ public class Donor
{
_coins += amount;
}
public List<CoinTransactionToken> getCoinTransactions()
{
return _coinTransactions;
}
}

View File

@ -0,0 +1,8 @@
package mineplex.core.donation.repository.token;
public class CoinTransactionToken
{
public long Date;
public String Source;
public int Amount;
}

View File

@ -9,5 +9,6 @@ public class DonorToken
public List<Integer> SalesPackages;
public List<String> UnknownSalesPackages;
public List<TransactionToken> Transactions;
public List<CoinTransactionToken> CoinRewards;
public int Coins;
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="StaffServer,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="StaffServer,"/>
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="StaffServer,"/>
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${resource}"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}/common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.StaffServer}"/>
</launchConfiguration>

View File

@ -10,6 +10,16 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>auto,full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/StaffBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>

View File

@ -0,0 +1,3 @@
name: StaffServer
main: mineplex.staffServer.StaffServer
version: 0.1

View File

@ -3,14 +3,19 @@ package mineplex.staffServer;
import mineplex.core.account.CoreClientManager;
import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter;
import mineplex.core.creature.Creature;
import mineplex.core.donation.DonationManager;
import mineplex.core.memory.MemoryFix;
import mineplex.core.monitor.LagMeter;
import mineplex.core.npc.NpcManager;
import mineplex.core.playerTracker.PlayerTracker;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.recharge.Recharge;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.updater.FileUpdater;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.password.Password;
import org.bukkit.plugin.java.JavaPlugin;
@ -31,9 +36,11 @@ public class StaffServer extends JavaPlugin
CommandCenter.Initialize(this);
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(clientManager);
Recharge.Initialize(this);
DonationManager donationManager = new DonationManager(this, webServerAddress);
new NpcManager(this, new Creature(this));
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
@ -43,5 +50,8 @@ public class StaffServer extends JavaPlugin
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());
new MemoryFix(this);
new FileUpdater(this, portal);
new CustomerSupport(this, clientManager, donationManager);
new Password(this);
}
}

View File

@ -1,18 +1,23 @@
package mineplex.staffServer.customerSupport;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.donation.DonationManager;
import mineplex.core.donation.Donor;
import mineplex.core.donation.repository.token.CoinTransactionToken;
import mineplex.core.donation.repository.token.TransactionToken;
public class CustomerSupport extends MiniPlugin
{
@ -20,6 +25,7 @@ public class CustomerSupport extends MiniPlugin
private DonationManager _donationManager;
private NautHashMap<Player, HashSet<String>> _agentCacheMap = new NautHashMap<Player, HashSet<String>>();
private SimpleDateFormat _date = new SimpleDateFormat("MM/dd/yy HH:mm");
public CustomerSupport(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
@ -52,10 +58,29 @@ public class CustomerSupport extends MiniPlugin
{
CoreClient client = _clientManager.Get(playerName);
Donor donor = _donationManager.Get(playerName);
caller.sendMessage(C.cDGreen + C.Strike + "=============================================");
caller.sendMessage(F.main(GetName(), "Name : " + F.elem(playerName)));
caller.sendMessage(F.main(GetName(), "Rank : " + F.elem(client.GetRank().Name)));
caller.sendMessage(F.main(GetName(),
"Rank : " + F.elem(client.GetRank().Name.isEmpty() ? "Regular" : client.GetRank().Name)));
//for (donor.GetUnknownSalesPackagesOwned())
for (CoinTransactionToken transaction : donor.getCoinTransactions())
{
if (transaction.Source.equalsIgnoreCase("purchase"))
caller.sendMessage("[" + _date.format(transaction.Date) + "] " + C.cYellow + transaction.Amount + " Coins");
}
for (TransactionToken transaction : donor.getTransactions())
{
if (transaction.Coins == 0 && transaction.Gems == 0 && transaction.SalesPackageName.contains("Gem Booster"))
caller.sendMessage("[" + _date.format(transaction.Date) + "] " + C.cGreen
+ transaction.SalesPackageName);
}
caller.sendMessage(C.cDGreen + C.Strike + "=============================================");
}
@EventHandler
public void removeMapping(PlayerQuitEvent event)
{
_agentCacheMap.remove(event.getPlayer());
}
}

View File

@ -28,7 +28,7 @@ public class Password extends MiniPlugin
@EventHandler
public void promptForPassword(final PlayerJoinEvent event)
{
event.getPlayer().sendMessage(F.main(GetName(), "Please enter the server password within 5 seconds."));
event.getPlayer().sendMessage(F.main(GetName(), "Please enter the server password within 10 seconds."));
GetPlugin().getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
@ -37,7 +37,7 @@ public class Password extends MiniPlugin
if (!_accepted.contains(event.getPlayer()))
event.getPlayer().kickPlayer("You don't know the password little twerp.");
}
}, 100L);
}, 200L);
}
public void checkPassword(Player caller, String attempt)

View File

@ -15,7 +15,7 @@ public class PasswordCommand extends CommandBase<Password>
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 1)
if (args != null && args.length == 1)
{
Plugin.checkPassword(caller, args[0]);
}

View File

@ -0,0 +1,6 @@
package mineplex.staffServer.salespackages;
public class MonthlyUltra
{
}

View File

@ -83,6 +83,7 @@
<Compile Include="Tokens\AccountBatchToken.cs" />
<Compile Include="Tokens\AccountNameToken.cs" />
<Compile Include="Tokens\Client\AccountTransactionToken.cs" />
<Compile Include="Tokens\Client\CoinTransactionToken.cs" />
<Compile Include="Tokens\Client\RankUpdateToken.cs" />
<Compile Include="Tokens\Client\DonationBenefitToken.cs" />
<Compile Include="Model\Server\PetExtra.cs" />

View File

@ -43,6 +43,7 @@
SalesPackages = new List<int>(),
UnknownSalesPackages = new List<string>(),
Transactions = new List<AccountTransactionToken>(),
CoinRewards = new List<CoinTransactionToken>(),
CustomBuilds = new List<CustomBuildToken>(),
Pets = new List<PetToken>(),
PetNameTagCount = account.PetNameTagCount

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LOC.Core.Tokens.Client
{
public class CoinTransactionToken
{
public long Date { get; set; }
public int Amount { get; set; }
public string Source { get; set; }
public CoinTransactionToken(Model.Sales.CoinTransaction transaction)
{
Amount = transaction.Amount;
Date = transaction.Date;
Source = transaction.Source;
}
}
}

View File

@ -1,6 +1,7 @@
namespace LOC.Core.Tokens.Client
{
using System.Collections.Generic;
using LOC.Core.Model.Sales;
public class DonorToken
{
@ -10,6 +11,7 @@
public List<int> SalesPackages { get; set; }
public List<string> UnknownSalesPackages { get; set; }
public List<AccountTransactionToken> Transactions { get; set; }
public List<CoinTransactionToken> CoinRewards { get; set; }
public List<CustomBuildToken> CustomBuilds { get; set; }
public List<PetToken> Pets { get; set; }
public int PetNameTagCount { get; set; }

View File

@ -687,7 +687,7 @@
repository.CommitChanges();
}
public Account GetAccountByUUID(string uuid)
public ClientToken GetAccountByUUID(string uuid)
{
using (var repository = _repositoryFactory.CreateRepository())
{
@ -698,7 +698,16 @@
account.LoadNavigationProperties(repository.Context);
return account;
ClientToken clientToken = null;
clientToken = new ClientToken(account);
foreach (var trans in repository.Where<CoinTransaction>(x => x.Account.AccountId == account.AccountId).ToList())
{
clientToken.DonorToken.CoinRewards.Add(new CoinTransactionToken(trans));
}
return clientToken;
}
}
}

View File

@ -39,6 +39,6 @@
bool CoinReward(GemRewardToken token);
Account GetAccountByUUID(string uuid);
ClientToken GetAccountByUUID(string uuid);
}
}

View File

@ -42,9 +42,7 @@
[HttpPost]
public ActionResult GetAccountByUUID(string uuid)
{
var account = _accountAdministrator.GetAccountByUUID(uuid);
var json = JsonConvert.SerializeObject(new ClientToken(account));
var json = JsonConvert.SerializeObject(_accountAdministrator.GetAccountByUUID(uuid));
return Content(json, "application/json");
}

File diff suppressed because it is too large Load Diff

Binary file not shown.