diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c27e9fd
--- /dev/null
+++ b/.gitignore
@@ -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
\ No newline at end of file
diff --git a/Grid.Friends.php b/Grid.Friends.php
new file mode 100644
index 0000000..b784e7d
--- /dev/null
+++ b/Grid.Friends.php
@@ -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 = "grid_instant_messageposition_x0position_y0position_z0to_agent_id".$toUUID."from_agent_session00000000-0000-0000-0000-000000000000im_session_id".$fromUUID."from_agent_name".$fromName."from_agent_id".$fromUUID."binary_bucketAA==region_handle0region_id00000000-0000-0000-0000-000000000000parent_estate_id1timestamp".time()."dialogAA==offlineAA==from_groupFALSEmessage".$text."";
+ 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'], "get_user_infouserID".$UUID."", "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.");
+ }
+ }
+ }
+?>
\ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index 19a1dd8..0000000
--- a/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# OpenSim.Robust.HGFriendsService
-
diff --git a/prebuild.xml b/prebuild.xml
new file mode 100644
index 0000000..52fef0a
--- /dev/null
+++ b/prebuild.xml
@@ -0,0 +1,39 @@
+
+
+
+ ../../../bin
+
+
+
+
+ ../../../bin
+
+
+
+ ../../../bin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/NEWHGFriendServerConnector.cs b/src/NEWHGFriendServerConnector.cs
new file mode 100644
index 0000000..6d965eb
--- /dev/null
+++ b/src/NEWHGFriendServerConnector.cs
@@ -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(theService, args);
+
+ theService = serverConfig.GetString("UserAgentService", string.Empty);
+ if (theService == String.Empty)
+ throw new Exception("No UserAgentService in " + m_ConfigName);
+ m_UserAgentService = ServerUtils.LoadPlugin(theService, new Object[] { config, localConn });
+
+ server.AddStreamHandler(new NEWHGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn));
+ }
+ }
+}
diff --git a/src/NEWHGFriendsServerPostHandler.cs b/src/NEWHGFriendsServerPostHandler.cs
new file mode 100644
index 0000000..125dd7a
--- /dev/null
+++ b/src/NEWHGFriendsServerPostHandler.cs
@@ -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 m_fixCache = new List();
+
+ 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(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 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;
+ }
+ }
+ }
+}