add old data

master
Christopher 2020-08-01 02:59:11 +02:00
parent 1355fce075
commit c47045028a
6 changed files with 714 additions and 2 deletions

290
.gitignore vendored Normal file
View File

@ -0,0 +1,290 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.csproj.user
*.csproj
*.dll.build
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

179
Grid.Friends.php Normal file
View File

@ -0,0 +1,179 @@
<? /*<[ Interval = 1800 ]>*/
require("../classes/Framework.php");
set_time_limit(0);
function getDataFromHTTP($URL, $contend = "", $requestTyp = "application/text")
{
try
{
if($contend != "")
{
return file_get_contents($URL, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 2, 'content' => $contend))));
}else{
return file_get_contents($URL);
}
} catch (Exception $e) {
echo "(HTTP REQUEST) error while conntect to remote server. : ".$URL;
dolog("FriendFix", "(HTTP REQUEST) error while conntect to remote server. : ".$URL);
}
}
function sendInworldIM($fromUUID, $toUUID, $fromName, $targetURL, $text)
{
$rawXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>grid_instant_message</methodName><params><param><value><struct><member><name>position_x</name><value><string>0</string></value></member><member><name>position_y</name><value><string>0</string></value></member><member><name>position_z</name><value><string>0</string></value></member><member><name>to_agent_id</name><value><string>".$toUUID."</string></value></member><member><name>from_agent_session</name><value><string>00000000-0000-0000-0000-000000000000</string></value></member><member><name>im_session_id</name><value><string>".$fromUUID."</string></value></member><member><name>from_agent_name</name><value><string>".$fromName."</string></value></member><member><name>from_agent_id</name><value><string>".$fromUUID."</string></value></member><member><name>binary_bucket</name><value><string>AA==</string></value></member><member><name>region_handle</name><value><i4>0</i4></value></member><member><name>region_id</name><value><string>00000000-0000-0000-0000-000000000000</string></value></member><member><name>parent_estate_id</name><value><string>1</string></value></member><member><name>timestamp</name><value><string>".time()."</string></value></member><member><name>dialog</name><value><string>AA==</string></value></member><member><name>offline</name><value><string>AA==</string></value></member><member><name>from_group</name><value><string>FALSE</string></value></member><member><name>message</name><value><string>".$text."</string></value></member></struct></value></param></params></methodCall>";
getDataFromHTTP($targetURL, $rawXML, "text/xml");
}
function getFullGridDomainList()
{
$Domains = array();
$gridUsers = $GLOBALS[MySql]->query("SELECT userID FROM ".$GLOBALS[GridSettings]["robustdb"].".griduser", array($LocalUserUUID));
while($UserData = $gridUsers->fetch())
{
$found = FALSE;
$data = explode(";", $UserData[userID]);
$userDomain = strtolower(trim($data[1]));
foreach($Domains as $domain)
if($userDomain == $domain)
{
$found = TRUE;
continue;
}
if($found == FALSE && $userDomain != "")
array_push($Domains, $userDomain);
}
return $Domains;
}
function getUserInfo($homeURI, $UUID)
{
try
{
$homeURIParts = parse_url($homeURI);
$HTTPUSerInfo = new SimpleXMLElement(getDataFromHTTP("http://".$homeURIParts['host'].":".$homeURIParts['port'], "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_user_info</methodName><params><param><value><struct><member><name>userID</name><value><string>".$UUID."</string></value></member></struct></value></param></params></methodCall>", "application/xml"));
$HTTPUSerInfo = $HTTPUSerInfo->params->param->value->struct->member;
$UserInfoData = array();
foreach($HTTPUSerInfo as $userRequestElement)
{
if($userRequestElement->value->string->__toString() != "")
$UserInfoData[strtoupper($userRequestElement->name->__toString())] = $userRequestElement->value->string->__toString();
if($userRequestElement->value->i4->__toString() != "")
$UserInfoData[strtoupper($userRequestElement->name->__toString())] = $userRequestElement->value->i4->__toString();
}
return $UserInfoData;
} catch (Exception $e) {
echo "(getUserInfo) error while getting data";
dolog("FriendFix", "(getUserInfo) error while getting data");
}
$UserInfoData = array();
$UserInfoData['RESULT'] = "failure";
return $UserInfoData;
}
function tryToGetUserDataFromHomeURIList($homeURLs, $UUID)
{
foreach($homeURLs as $url)
{
$tempUserData = getUserInfo($url, $UUID);
$tempUserData['HOMEURL'] = $url;
if($tempUserData['RESULT'] != "failure")
{
return $tempUserData;
}
}
return array();
}
$AllGrids = HTTP_Request($GLOBALS[Sqlite]->setting("SMTP.ORIGIN")."/opensim/triggers", "pass=".$GLOBALS[Sqlite]->setting("MANAGER.AUTH.PASS"), "", 3, "application/x-www-form-urlencoded");
if (empty($AllGrids))
{
dolog("FriendFix", "Grids konnten nicht abgerufen werden!");
die("Grids konnten nicht abgerufen werden!");
}
$AllGrids = json_decode($AllGrids, true);
dolog("FriendFix", count($AllGrids)." Grids gefunden...");
for ($z = 0; $z < count($AllGrids); ++$z)
{
RequestGridSpecificData($GLOBALS[Sqlite]->setting("SMTP.ORIGIN"), $AllGrids[$z]);
if ($GLOBALS[GridSettings]["hasrobust"] == "1")
{
if(is_file(dirname($GLOBALS[GridSettings]["osbasepath"])."/friends.txt"))
{
$FriendFixFile = explode("\n", file_get_contents(dirname($GLOBALS[GridSettings]["osbasepath"])."/friends.txt"));
foreach ($FriendFixFile as $rawLine)
{
$DataLine = trim($rawLine);
$LineData = explode(";", $DataLine);
if(count($LineData) == 5)
{
$LocalUserUUID = $LineData[1];
$RemoteUserUUID = $LineData[0];
$LocalAvatarName = "Unknown User";
$AvatarData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".useraccounts WHERE PrincipalID = '{0}' LIMIT 1", array($LocalUserUUID))->fetch();
$RemoteUserData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".griduser WHERE userID LIKE '{0}' LIMIT 1", array($RemoteUserUUID."%"))->fetch();
if(!empty($AvatarData))
$LocalAvatarName = $AvatarData[FirstName]." ".$AvatarData[LastName];
if (!empty($RemoteUserData))
{
$DBUserData = explode(";", $RemoteUserData[UserID]);
if(count($DBUserData) == 3)
{
$RemoteUserString = $LineData[0].";".$DBUserData[1].";".$DBUserData[2].";".$LineData[4];
$FriendData = $GLOBALS[MySql]->query("SELECT * FROM ".$GLOBALS[GridSettings]["robustdb"].".friends WHERE Friend LIKE '{0}' LIMIT 1", array($RemoteUserUUID."%"))->fetch();
if(empty($FriendData))
{
echo "Generiere freundschaft für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID."(".$DBUserData[2]."@".$DBUserData[1].").\n";
dolog("FriendFix", "Generiere freundschaft für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID."(".$DBUserData[2]."@".$DBUserData[1].").");
sendInworldIM("00000000-0000-0000-0000-000000000000", $LocalUserUUID, "GRID SERVICE", $GLOBALS[GridSettings][robust], "Es wurde eine Freundschaft für '".$DBUserData[2]." @ ".$DBUserData[1]."' generiert.");
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".friends (PrincipalID, Friend) VALUES ('{0}', '{1}')", array($LocalUserUUID, $RemoteUserString));
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".friends (PrincipalID, Friend) VALUES ('{0}', '{1}')", array($RemoteUserString, $LocalUserUUID));
}
}
}else{
echo "Kann User ".$RemoteUserUUID." für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID." nicht in der DB finden.\n";
dolog("FriendFix", "Kann User ".$RemoteUserUUID." für ".$LocalUserUUID."(".$LocalAvatarName.")<->".$RemoteUserUUID." nicht in der DB finden.");
$userData = tryToGetUserDataFromHomeURIList(getFullGridDomainList(), $RemoteUserUUID);
if(count($userData) != 0)
{
echo "Erfolgreich Remotedaten zu User ".$RemoteUserUUID." abrufen: ".str_replace("\r", "", str_replace("\n", "", print_r($userData, true)))."\n";
dolog("FriendFix", "Erfolgreich Remotedaten zu User ".$RemoteUserUUID." abrufen: ".str_replace("\r", "", str_replace("\n", "", print_r($userData, true))));
//echo $RemoteUserUUID.";".$userData['HOMEURL'].";".$userData['USER_FIRSTNAME']." ".$userData['USER_LASTNAME'];
$GLOBALS[MySql]->query("INSERT INTO ".$GLOBALS[GridSettings]["robustdb"].".griduser (UserID) VALUES ('{0}')", array($RemoteUserUUID.";".$userData['HOMEURL'].";".$userData['USER_FIRSTNAME']." ".$userData['USER_LASTNAME']));
}else{
echo "Kann keine Remotedaten für User ".$RemoteUserUUID." abrufen. Dieser User ist keinem Grid bekannt.\n";
dolog("FriendFix", "Kann keine Remotedaten für User ".$RemoteUserUUID." abrufen. Dieser User ist keinem Grid bekannt.");
}
}
}
}
}else{
echo "Konnte keine Daten für das Grid '".$AllGrids[$z]."' finden.";
dolog("FriendFix", "Konnte keine Daten für das Grid '".$AllGrids[$z]."' finden.");
}
}
}
?>

View File

@ -1,2 +0,0 @@
# OpenSim.Robust.HGFriendsService

39
prebuild.xml Normal file
View File

@ -0,0 +1,39 @@
<Project frameworkVersion="v4_0" name="OpenSim.Robust.HGFriendsService" path="addon-modules/OpenSim.Robust.HGFriendsService/src" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../bin</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../bin</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../bin</ReferencePath>
<Reference name="System" localCopy="false"/>
<Reference name="System.Xml"/>
<Reference name="System.Drawing"/>
<Reference name="System.Runtime.Remoting"/>
<Reference name="Axiom.MathLib.dll" path="../../bin"/>
<Reference name="Nini.dll" path="../../../bin"/>
<Reference name="log4net.dll" path="../../../bin"/>
<Reference name="XMLRPC.dll" path="../../../bin"/>
<Reference name="Mono.Addins.dll" path="../../../bin"/>
<Reference name="OpenMetaverseTypes.dll" path="../../../bin"/>
<Reference name="OpenMetaverse.dll" path="../../../bin"/>
<Reference name="HttpServer_OpenSim.dll" path="../../../bin"/>
<Reference name="OpenSim.Region.Framework" path="../../../bin"/>
<Reference name="OpenSim.Framework" path="../../../bin"/>
<Reference name="OpenSim.Framework.Console" path="../../../bin"/>
<Reference name="OpenSim.Framework.Servers" path="../../../bin"/>
<Reference name="OpenSim.Framework.Servers.HttpServer" path="../../../bin"/>
<Reference name="OpenSim.Server.Handlers" path="../../../bin"/>
<Reference name="OpenSim.Server.Base" path="../../../bin"/>
<Reference name="OpenSim.Services.Interfaces" path="../../../bin"/>
<Reference name="OpenSim.Server.Base" path="../../../bin"/>
<Reference name="OpenSim.Data" path="../../../bin"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using Nini.Config;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Server.Handlers.Base;
using log4net;
using System.Reflection;
namespace OpenSim.Server.Handlers.Hypergrid
{
public class NEWHGFriendsServerConnector : ServiceConnector
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IUserAgentService m_UserAgentService;
private IHGFriendsService m_TheService;
private string m_ConfigName = "HGFriendsService";
// Called from Robust
public NEWHGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) : this(config, server, configName, null)
{
m_log.Info("Loaded NEWHGFriendsServerConnector (GRID)");
}
// Called from standalone configurations
public NEWHGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName, IFriendsSimConnector localConn) : base(config, server, configName)
{
if (configName != string.Empty)
m_ConfigName = configName;
Object[] args = new Object[] { config, m_ConfigName, localConn };
IConfig serverConfig = config.Configs[m_ConfigName];
if (serverConfig == null)
throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
string theService = serverConfig.GetString("LocalServiceModule",
String.Empty);
if (theService == String.Empty)
throw new Exception("No LocalServiceModule in config file");
m_TheService = ServerUtils.LoadPlugin<IHGFriendsService>(theService, args);
theService = serverConfig.GetString("UserAgentService", string.Empty);
if (theService == String.Empty)
throw new Exception("No UserAgentService in " + m_ConfigName);
m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, new Object[] { config, localConn });
server.AddStreamHandler(new NEWHGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn));
}
}
}

View File

@ -0,0 +1,128 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Nini.Config;
using log4net;
using System;
using System.Reflection;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenMetaverse;
using OpenSim.Framework.ServiceAuth;
namespace OpenSim.Server.Handlers.Hypergrid
{
public class NEWHGFriendsServerPostHandler : BaseStreamHandler
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IUserAgentService m_UserAgentService;
private IFriendsSimConnector m_FriendsLocalSimConnector;
private IHGFriendsService m_TheService;
private HGFriendsServerPostHandler m_realHandler = null;
List<String> m_fixCache = new List<String>();
public NEWHGFriendsServerPostHandler(IHGFriendsService service, IUserAgentService uas, IFriendsSimConnector friendsConn) : base("POST", "/hgfriends")
{
Console.WriteLine("----------- LOADING NEWHGFriendsServerPostHandler -----------");
m_TheService = service;
m_UserAgentService = uas;
m_FriendsLocalSimConnector = friendsConn;
m_realHandler = new HGFriendsServerPostHandler(service, uas, friendsConn);
if (File.Exists("../friends.txt"))
m_fixCache = new List<String>(File.ReadAllLines("../friends.txt"));
}
public static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
protected override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
try
{
using (StreamReader _streamReader = new StreamReader(requestData))
{
String body = _streamReader.ReadToEnd();
//m_log.Info("BODY: " + body);
Dictionary<string, object> request = ServerUtils.ParseQueryString(body);
if (request.ContainsKey("userID"))
{
string userID = request["userID"].ToString();
if (request.ContainsKey("METHOD"))
{
if(request["METHOD"].ToString() == "statusnotification")
{
for (int _friendID = 0; request.ContainsKey("friend_" + _friendID); _friendID++)
{
String FriendData = userID + ";" + request["friend_" + _friendID].ToString().Trim();
if (!m_fixCache.Contains(FriendData))
m_fixCache.Add(FriendData);
}
}
}
}
lock(m_fixCache)
{
File.WriteAllLines("../friends.txt", m_fixCache.ToArray());
}
return m_realHandler.Handle(path, GenerateStreamFromString(body), httpRequest, httpResponse);
}
}catch(Exception _e)
{
m_log.Info("EXAPTION: " + _e.Message);
return null;
}
}
}
}