1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-30 08:07:46 +00:00

Merge pull request #7 from amibu01/master

Added PoC PS4 Support back
This commit is contained in:
SapphireMordred 2017-08-08 22:50:47 +02:00 committed by GitHub
commit e81d7c2538
5 changed files with 185 additions and 0 deletions

View file

@ -0,0 +1,76 @@
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FFXIV 1.0 Login</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/global.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script>
function doLogin(){
var url = "sapphire-api/lobby/insertSession";
var params = "{\"sId\":\"" + document.getElementsByName('sid')[0].value + "\",\"secret\":\"" + document.getElementsByName('secret')[0].value + "\",\"accountId\":\"" + document.getElementsByName('accountId')[0].value + "\"}";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
try{
var response = readBody(xhr);
alert(response);
var parsed = JSON.parse(response);
}catch(err){
}
}
}
xhr.send(params);
}
function readBody(xhr) {
var data;
if (!xhr.responseType || xhr.responseType === "text") {
data = xhr.responseText;
} else if (xhr.responseType === "document") {
data = xhr.responseXML;
} else {
data = xhr.response;
}
return data;
}
</script>
</head>
<body oncontextmenu="return false;">
<div style="width: 80%; height: 300px; margin-left: auto; margin-right: auto; margin-top: 20%">
<div class="contentContainer" >
<img style="width: 100%;" src="./sapphire_logo.png" />
</div>
<div class="contentContainer">
<div class="info">
<br />
<table class="infoForm">
<tr>
<td>Secret:</td>
<td><input type="text" name="secret" /></td>
</tr>
<tr>
<td>sId:</td>
<td><input type="password" name="sid" /></td>
</tr>
<tr>
<td>accountId:</td>
<td><input type="password" name="accountId" /></td>
</tr>
<tr>
<td colspan="2">
<input id="submitButton" type="button" value="insert" onclick="doLogin();" />
</td>
</tr>
</table>
<p class="errorMessage" id="errorMessage"></p>
</div>
</div>
</div>
</body>
</html>

View file

@ -70,6 +70,20 @@ bool Core::Network::SapphireAPI::login( const std::string& username, const std::
} }
bool Core::Network::SapphireAPI::insertSession( const uint32_t& accountId, std::string& sId )
{
// create session for the new sessionid and store to sessionlist
auto pSession = boost::make_shared< Session >();
pSession->setAccountId( accountId );
pSession->setSessionId( (uint8_t *)sId.c_str() );
m_sessionMap[sId] = pSession;
return true;
}
bool Core::Network::SapphireAPI::createAccount( const std::string& username, const std::string& pass, std::string& sId ) bool Core::Network::SapphireAPI::createAccount( const std::string& username, const std::string& pass, std::string& sId )
{ {
// get account from login name // get account from login name

View file

@ -31,6 +31,8 @@ namespace Core
void deleteCharacter( std::string name, uint32_t accountId ); void deleteCharacter( std::string name, uint32_t accountId );
bool insertSession( const uint32_t& accountId, std::string& sId );
std::vector<Core::PlayerMinimal> getCharList( uint32_t accountId ); std::vector<Core::PlayerMinimal> getCharList( uint32_t accountId );
bool checkNameTaken( std::string name ); bool checkNameTaken( std::string name );

View file

@ -289,6 +289,46 @@ int main()
}; };
server.resource["^/sapphire-api/lobby/insertSession"]["POST"] = [&server]( shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request ) {
print_request_info( request );
try
{
using namespace boost::property_tree;
ptree pt;
read_json( request->content, pt );
std::string sId = pt.get<string>( "sId" );
uint32_t accountId = pt.get<uint32_t>( "accountId" );
std::string secret = pt.get<string>( "secret" );
auto m_pConfig = new Core::XMLConfig();
if( !m_pConfig->loadConfig( "config/settings_rest.xml" ) )
{
g_log.fatal( "Error loading config settings_rest.xml" );
return 1;
}
if( m_pConfig->getValue< std::string >( "Settings.General.ServerSecret" ) != secret ) {
std::string json_string = "{\"result\":\"invalid_secret\"}";
*response << "HTTP/1.1 403\r\nContent-Length: " << json_string.length() << "\r\n\r\n" << json_string;
}
else
{
g_sapphireAPI.insertSession( accountId, sId );
std::string json_string = "{\"result\":\"success\"}";
*response << "HTTP/1.1 200\r\nContent-Length: " << json_string.length() << "\r\n\r\n" << json_string;
}
}
catch( exception& e )
{
*response << "HTTP/1.1 500\r\n\r\n";
g_log.error( e.what() );
}
};
server.resource["^/sapphire-api/lobby/checkNameTaken"]["POST"] = [&server]( shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request ) { server.resource["^/sapphire-api/lobby/checkNameTaken"]["POST"] = [&server]( shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request ) {
print_request_info( request ); print_request_info( request );

View file

@ -0,0 +1,53 @@
import socket
from urllib2 import urlopen
class DNSQuery:
def __init__(self, data):
self.data=data
self.domain=''
qtype = (ord(data[2]) >> 3) & 15 # Opcode bits
if qtype == 0: # Standard query
index=12
lon=ord(data[index])
while lon != 0:
self.domain+=data[index+1:index+lon+1]+'.'
index+=lon+1
lon=ord(data[index])
def request(self, ip):
packet=''
if self.domain:
packet+=self.data[:2] + "\x81\x80"
packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00' # Questions and Answers Counts
packet+=self.data[12:] # Original Domain Name Question
packet+='\xc0\x0c' # Pointer to domain name
packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04' # Response type, ttl and resource data length -> 4 bytes
packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
return packet
if __name__ == '__main__':
#ip=socket.gethostbyname(socket.gethostname())
#ip = urlopen('http://ip.42.pl/raw').read()
ip = "212.43.86.40"
print 'DNS server started on %s intercepting to %s' % (socket.gethostbyname(socket.gethostname()), ip)
udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udps.bind(('',53))
try:
while 1:
data, addr = udps.recvfrom(1024)
p=DNSQuery(data)
if "neolobby" in p.domain:
udps.sendto(p.request(ip), addr) #send answer
print 'Intercepted request: %s -> %s' % (p.domain, ip)
else:
try:
r_ip = socket.gethostbyname(p.domain)
except:
r_ip = ip
udps.sendto(p.request(r_ip), addr) #send answer
print 'Normal request: %s -> %s' % (p.domain, r_ip)
except KeyboardInterrupt:
udps.close()