Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Sno

#1
In case you need it:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;
import java.util.Vector;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import de.stefan1200.jts3serverquery.JTS3ServerQuery;

public class JTS3TimeZone {
private boolean DEBUG;
JTS3ServerQuery queryLib;
HashMap<String, String> clientInfo;
HashMap<Integer, TimeZone> clientZone;
// If you don't have an API_KEY yet, you can get one for free by registering at http://www.ipinfodb.com/register.php.
private final String apiKey = ;

public JTS3TimeZone(
JTS3ServerQuery queryLib) {
clientZone = new HashMap<Integer, TimeZone>();
this.queryLib = queryLib;
// DEBUG = true;
}

public TimeZone getTimeZone(Integer clientID) {
TimeZone result;
if (clientZone.containsKey(clientID)) {
result = clientZone.get(clientID);
} else {
result = getTimeZone(getIpAddress(clientID));
clientZone.put(clientID, result);
}
return getTimeZone(getIpAddress(clientID));
}

public TimeZone getTimeZone(String ipAddress) {
TimeZone result = null;
URL localURL;
try {
localURL = new URL("http://api.ipinfodb.com/v3/ip-city/?format=json&key=" + apiKey + "&ip=" + ipAddress);
URLConnection localURLConnection = localURL.openConnection();
localURLConnection.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01");
localURLConnection.setRequestProperty("Accept-Language", "es-es,es;q=0.8,en-us;q=0.5,en;q=0.3");
localURLConnection.setRequestProperty("Accept-Encoding", "paco");
localURLConnection.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
localURLConnection.setRequestProperty("Connection", "close");
localURLConnection.setRequestProperty("X-Requested-With", "XMLHttpRequest");
localURLConnection.setConnectTimeout(10000);

BufferedReader clanBufferedReader = null;
StringBuilder data = new StringBuilder(3000);
try {
clanBufferedReader = new BufferedReader(new InputStreamReader(localURLConnection.getInputStream(), "UTF8"));
for (String line; (line = clanBufferedReader.readLine()) != null; data.append(line.replace(" ", "").replace("\t", "")))
;
} finally {
if (clanBufferedReader != null)
clanBufferedReader.close();
}
if (DEBUG)
System.out.println(data);
JsonParser jsonParser = new JsonParser();
JsonObject json = jsonParser.parse(data.toString()).getAsJsonObject();

if (!"ok".equalsIgnoreCase(json.get("statusCode").getAsString())) {
throw new Exception("Error in API status: " + json.get("statusMessage").getAsString());
}

result = TimeZone.getTimeZone("GMT" + json.get("timeZone").getAsString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}

private String getIpAddress(int clientID) {
return queryLib.getInfo(JTS3ServerQuery.INFOMODE_CLIENTINFO, clientID).get("connection_client_ip");
}
}
#2
Since the new versions of TS don't seem to have anywhere that displays the channel ID # (and not even a serverquery window in the client) I had been finding them by logging in an old client that does show them. But now the newest server version won't let older clients connect, so finding those #'s for config purposes is impossible with a standard client. So I wrote function for the bot that tells the bot's admin those numbers that you might want to include. Here's the code:
Add this to JTS3ServerMod.handleChatMessage():

} else if (msg.toLowerCase().startsWith("!channels")) {
chatCommands.handleChannels(eventInfo);


And stick this somewhere in ChatCommands.java:
void handleChannels(HashMap<String, String> eventInfo) {
modClass.addLogEntry("COMMAND", "Got command from " + eventInfo.get("invokername"), false);
Vector<HashMap<String, String>> channelList = queryLib.getList(JTS3ServerQuery.LISTMODE_CHANNELLIST);
StringBuilder msg = new StringBuilder(1023);
Integer lastPid = 0;
Integer newPid;
Integer indent = 0;
Vector<Integer> indentLvls = new Vector<Integer>(10);
for (HashMap<String, String> channel : channelList) {
msg.append("\n");
newPid = Integer.parseInt(channel.get("pid"));
if (newPid == 0) {
indent = 0;
indentLvls.clear();
} else if (newPid > lastPid) {
indentLvls.add(newPid);
indent++;
} else if (newPid < lastPid) {
indent = indentLvls.indexOf(newPid) + 1;
indentLvls.setSize(indent);
}
lastPid = newPid;
if (indent > 0) {
for (int i = 0; i < indent; i++) {
msg.append("\t");
}
}
msg.append(channel.get("channel_name") + ": " + channel.get("cid"));
if (msg.length() + 42 + indent > 1023) {
queryLib.sendTextMessage(Integer.parseInt(eventInfo.get("invokerid")), JTS3ServerQuery.TEXTMESSAGE_TARGET_CLIENT, msg.toString());
msg = new StringBuilder(1023);
}
}
if (msg.length() > 0)
queryLib.sendTextMessage(Integer.parseInt(eventInfo.get("invokerid")), JTS3ServerQuery.TEXTMESSAGE_TARGET_CLIENT, msg.toString());
}


Now bot admins can get a nicely formatted list of the channels with their ID's which are needed to config many of the bot's functions by messaging the bot with "!channels".
Cheers  8)
#3
Quote from: Stefan1200 on March 06, 2013, 08:46:00 PM
The TS3 server don't know the timezone. Country really just knows the country, which might be also useful for you, if you have a list of country => timezone.
Most of the clients on the server I run this on are in North America, so using country for timezone won't work
Quote from: Stefan1200 on March 06, 2013, 08:46:00 PM
The  client_ip will be displayed at the client information, if the TS3 bot has the permission to see the client ip. Currently I don't know if there is also a way to see the IP at the client list.
Awesome, figured it out, now just need to make a class that retrieves timezones from geo locations obtained from an ip lookup

thanks, I keep figuring out ways  to use JTS3ServerMod/JTS3ServerQuery to automate some seriously cool stuff

btw i've figured out how to add things like a dice roller, joke teller, and a bunch of other stuff. it's almost as functional as a good mIrc bot (almost got trivia working). With plans i have it won't be long before i'll need it to utilize an sqlite or mysql db
#4
Howdy,
I've heavily extended  JTS3ServerMod with a bunch of  features. One of  them  reports clan battle schedules for the game "World of tanks," and I was wondering if it's possible to find out what timezone a client is in? So when the clients send it a !battles command it can adjust the battle times to match their time zone in the response. It also pushes notifications to clients when the battle schedule changes and it'd be nice to have the notifications be adjusted to each client's timezone.

I've figured out how  to get what country a client is in by using eventInfo.get("invokerid") to lookup a client in a list created by:Vector<HashMap<String,String>> clientList = queryLib.getList(JTS3ServerQuery.LISTMODE_CLIENTLIST, "-uid,-country");But can't find anything about the timezone they're in.  ???

If timezone info isn't available in teamspeak, how do I retrieve a client's ip address using JTS3ServerMod/JTS3ServerQuery? I know that info is available in a normal TS client by right clicking a user and hitting "connection info." If I can get their ip address i can find thier timezone using http://ipinfodb.com/ip_location_api.php

Cheers,
8)
#5
cool thanks. What about banning? Reason for wanting an ip was to be able to set a ban to it to prevent them from just being able to change thier name and come back in.
#6
Is there a way to return a client's ip, and/or add a ban? Can't find any methods for that in  JTS3ServerQuery
#7
it would be possible to send a message to every client (either poke or privatemsg) instead of every channel
#8
Didn't know a channel could be muted, I just set the away channel to be the lowest quality audio quality to minimize bandwidth. If a channel is muted would trying to speak change the player's idle time even if there's no sound?

I didn't know if auto-follow would make sense, which is why I was wondering if the channel the bot was in effected anything. If the channel it's in does effect things then having it follow could be useful, if not then true there would be no point for an auto-follow.

I've got an idea looking through the code on how I could implement attendance. During a certain time frame it would check if a player is in a certain channel similar to how it checks their idle time. If they are it'd record their name and date to a new log file. Then I can have my old program scan that log at the end of the day the same way I had it scanning the mumble log previously. I'm pretty sure I can figure out how how to do that. What I'm not sure about is how I'd have it only add a player if they weren't already added for that day. Also, ideally it would only add them if they've been in the channel (or sub-channel of the designated channel) for over an hour so that way players can't login, go to the designated channel, then logoff, just to get accounted for that day to increase the amount of currency they'd receive.
#9
First I'd like to say outstanding work! I've used the bot for a day and it's already proven to be invaluable.

I especially like the autoidle and autoaway features. A suggestion I have is to add the auto-move-back functionality that autoaway can have to the autoidle feature. If a clan member gets flagged as being idle too long because they haven't said anything in a while (I'm aware that detecting an idle mouse/keyboard can only be done client-side and isn't possible for the bot) during a clan battle, they have to minimize the game in order to switch back to the appropriate channel. This could cause disaster for the battle! If an auto-move-back were to be implemented, when they get moved due to not speaking in a while, all they need to do is say something and they'd be placed back in the battle channel.

Some questions I have are:

  • Does the channel that the bot is in effect any of it's features? If so an auto-follow feature would be useful so you could tell the bot to follow you around if you switch channels
  • Is it possible to send messages to channels in response to things people type in them even if the bot isn't in that channel? If so, features similar to other plugins people have made would be possible like !dice, !slap, !trivia, etc. But would be more powerful since they could be done from anywhere on the server instead of needing someone with a plugin installed to be present in the channel you're in.
  • If an !exec  command is sent, what kind of command should be used? Is this for TS server query commands or system/shell commands?

My clan plays a game where in-game-currency is given to the clan based on territories it owns. Twice a month we disperse the currency to our members and each member receives a percentage of what is given out based on their attendance during prime battle hours. The way it's calculated is by a program I wrote that scans the mumble log (we've been using mumble and would like to switch to teamspeak), and if a member joins the "staging area" channel during prime battle hours it updates a google spreadsheet doc indicating that member was present for that day. A formula in the spreadsheet then adds together all the times that member was present during the "pay period" and divides it by the total number of times people showed up for that period to get that person's percentage. The total amount of currency to be given out is multiplied by that percentage in another formula which lets us know exactly how much currency that person should receive. Teamspeak's server logs don't record people entering or leaving a channel (or perhaps I just haven't been able to figure out how to have it record that), so we need another method to record attendance. I'm thinking about extending/adding a feature to JTS3ServerMod that would do this, and am hoping you could offer advice or tips on how to go about making it. I'm slightly new to java, but understand the basics fairly well and know several other languages (python being my strongest).

Thanks again for your wonderful bot! Keep up the good work!