Implement most HTTP parts of the protocol

This commit is contained in:
Cameron Gutman 2013-09-21 02:33:52 -04:00
parent 00fca9462c
commit b263367528
5 changed files with 151 additions and 2 deletions

View File

@ -7,6 +7,7 @@
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"

View File

@ -27,9 +27,7 @@ public final class R {
public static final int activity_connection=0x7f030000;
}
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
public static final class style {
/**

View File

@ -1,5 +1,11 @@
package com.limelight;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
import com.limelight.nvstream.NvConnection;
import android.os.Bundle;
import android.app.Activity;
@ -9,6 +15,23 @@ public class Connection extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connection);
new Thread(new Runnable() {
@Override
public void run() {
try {
new NvConnection("141.213.191.238").doShit();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}

View File

@ -0,0 +1,31 @@
package com.limelight.nvstream;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
public class NvConnection {
private String host;
public NvConnection(String host)
{
this.host = host;
}
public void doShit() throws XmlPullParserException, IOException
{
NvHttp h = new NvHttp(host, "b0:ee:45:57:5d:5f");
System.out.println("Shield Shit");
System.out.println(h.getAppVersion());
System.out.println(h.getPairState());
int sessionId = h.getSessionId();
System.out.println("Session ID: "+sessionId);
int appId = h.getSteamAppId(sessionId);
System.out.println("Steam app ID: "+appId);
int gameSession = h.launchApp(sessionId, appId);
System.out.println("Started game session: "+gameSession);
}
}

View File

@ -0,0 +1,96 @@
package com.limelight.nvstream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Stack;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class NvHttp {
private String host;
private String macAddress;
public static final int PORT = 47989;
public NvHttp(String host, String macAddress)
{
this.host = host;
this.macAddress = macAddress;
}
private String getXmlString(InputStream in, String attribute) throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new InputStreamReader(in));
int eventType = xpp.getEventType();
Stack<String> currentTag = new Stack<String>();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_TAG) {
currentTag.push(xpp.getName());
for (int i = 0; i < xpp.getAttributeCount(); i++)
{
if (xpp.getAttributeName(i).equals(attribute))
return xpp.getAttributeValue(i);
}
} else if (eventType == XmlPullParser.END_TAG) {
currentTag.pop();
} else if (eventType == XmlPullParser.TEXT) {
if (currentTag.peek().equals(attribute)) {
return xpp.getText();
}
}
eventType = xpp.next();
}
return null;
}
private InputStream openHttpConnection(String url) throws IOException
{
return new URL(url).openConnection().getInputStream();
}
public String getAppVersion() throws XmlPullParserException, IOException
{
InputStream in = openHttpConnection("http://"+host+":"+PORT+"/appversion");
return getXmlString(in, "appversion");
}
public boolean getPairState() throws IOException, XmlPullParserException
{
InputStream in = openHttpConnection("http://"+host+":"+PORT+"/pairstate?mac="+macAddress);
String paired = getXmlString(in, "paired");
return Integer.valueOf(paired) != 0;
}
public int getSessionId() throws IOException, XmlPullParserException
{
InputStream in = openHttpConnection("http://"+host+":"+PORT+"/pair?mac="+macAddress+"&devicename=ANDROID");
String sessionId = getXmlString(in, "sessionid");
return Integer.valueOf(sessionId);
}
public int getSteamAppId(int sessionId) throws IOException, XmlPullParserException
{
InputStream in = openHttpConnection("http://"+host+":"+PORT+"/applist?session="+sessionId);
String appId = getXmlString(in, "ID");
return Integer.valueOf(appId);
}
// Returns gameSession XML attribute
public int launchApp(int sessionId, int appId) throws IOException, XmlPullParserException
{
InputStream in = openHttpConnection("http://"+host+":"+PORT+"/launch?session="+sessionId+"&appid="+appId);
String gameSession = getXmlString(in, "gamesession");
return Integer.valueOf(gameSession);
}
}