Created
January 5, 2017 11:23
-
-
Save johnou/9ec2bcc4688f6414329d85d5dc21f289 to your computer and use it in GitHub Desktop.
Facebook Arcade PipeServer emulator
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.IO.Pipes; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace PipeDream | |
{ | |
class FacebookArcadePipeServer | |
{ | |
private static string _userId = ""; | |
private static string _accessToken = ""; | |
static void Main(string[] args) | |
{ | |
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("FacebookArcadePipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) | |
{ | |
Console.WriteLine("Waiting for client.."); | |
pipeServer.BeginWaitForConnection(new AsyncCallback(ConnectionCallback), pipeServer); | |
Console.ReadKey(); | |
} | |
} | |
private static readonly byte[] _buffer = new byte[1024]; | |
private static void ReceiveCallback(IAsyncResult result) | |
{ | |
NamedPipeServerStream stream = (NamedPipeServerStream)result.AsyncState; | |
int bytesRead = stream.EndRead(result); | |
if (bytesRead > 0) | |
{ | |
byte[] received = new byte[bytesRead]; | |
Array.Copy(_buffer, received, bytesRead); | |
// TODO: process received | |
Console.WriteLine("Received: " + System.Text.Encoding.UTF8.GetString(received, 0, received.Length)); | |
// <LoginRequest><AppId>xxx</AppId><Permissions /></LoginRequest> | |
// https://developers.facebook.com/tools/accesstoken/?app_id=xxx | |
long epochTicks = new DateTime(1970, 1, 1).Ticks; | |
long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond); | |
//string responsev1 = "<LoginResponse><expiresIn>0</expiresIn><grantedScopes>email,public_profile</grantedScopes><userID>" + userId + "</userID><accessToken>" + accessToken + "</accessToken></LoginResponse>"; | |
string responsev2 = "<LoginResponse><last_refresh>0</last_refresh><expiration_timestamp>0</expiration_timestamp><permissions>email,public_profile</permissions><user_id>" | |
+ _userId + "</user_id><access_token>" + _accessToken + "</access_token></LoginResponse>"; | |
byte[] buffer = ASCIIEncoding.ASCII.GetBytes(responsev2); | |
stream.Write(buffer, 0, buffer.Length); | |
stream.Flush(); | |
Console.WriteLine("Sent: " + responsev2); | |
stream.BeginRead(_buffer, 0, _buffer.Length, ReceiveCallback, stream); | |
} | |
} | |
private static void ConnectionCallback(IAsyncResult result) | |
{ | |
NamedPipeServerStream stream = (NamedPipeServerStream)result.AsyncState; | |
stream.EndWaitForConnection(result); | |
Console.WriteLine("Client connected!"); | |
stream.BeginRead(_buffer, 0, _buffer.Length, ReceiveCallback, stream); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment