freeso/TSOClient/FSO.Common.DatabaseService/DatabaseService.cs

141 lines
4.7 KiB
C#
Raw Permalink Normal View History

using FSO.Common.DatabaseService.Model;
using FSO.Common.Serialization.Primitives;
using FSO.Common.Utils;
2015-09-04 17:58:22 +01:00
using FSO.Server.Clients;
using FSO.Server.Protocol.Voltron.Model;
using FSO.Server.Protocol.Voltron.Packets;
using Ninject;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace FSO.Common.DatabaseService
2015-09-04 17:58:22 +01:00
{
public class DatabaseService : IDatabaseService, IAriesMessageSubscriber
2015-09-04 17:58:22 +01:00
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
//private static Logger LOG = LogManager.GetCurrentClassLogger();
public static object Sync = new object();
2015-09-04 17:58:22 +01:00
public bool IsConnected => CityClient.IsConnected;
private uint messageId;
private AriesClient CityClient;
private Dictionary<uint, PendingRequest> PendingRequests = new Dictionary<uint, PendingRequest>();
2015-09-04 17:58:22 +01:00
public DatabaseService([Named("City")] AriesClient cityClient)
2015-09-04 17:58:22 +01:00
{
CityClient = cityClient;
CityClient.AddSubscriber(this);
2015-09-04 17:58:22 +01:00
}
public Task<GetTop100Response> GetTop100(GetTop100Request request)
{
return Request<GetTop100Response>(DBRequestType.GetTopResultSetByID, DBResponseType.GetTopResultSetByID, null, request);
}
public Task<LoadAvatarByIDResponse> LoadAvatarById(LoadAvatarByIDRequest request)
{
2015-09-04 17:58:22 +01:00
return Request<LoadAvatarByIDResponse>(DBRequestType.LoadAvatarByID, DBResponseType.LoadAvatarByID, null, request);
}
public Task<SearchResponse> Search(SearchRequest request, bool exact)
{
var requestType = exact ? DBRequestType.SearchExactMatch : DBRequestType.Search;
var responseType = exact ? DBResponseType.SearchExactMatch : DBResponseType.Search;
return Request<SearchResponse>(requestType, responseType, null, request);
}
2015-09-04 17:58:22 +01:00
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
//[MethodImpl(MethodImplOptions.Synchronized)]
2015-09-04 17:58:22 +01:00
private Task<T> Request<T>(DBRequestType type, DBResponseType responseType, uint? parameter, object complexParameter)
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
lock (Sync)
2015-09-04 17:58:22 +01:00
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
var id = NextMessageId();
var taskSource = new TaskCompletionSource<T>();
var pending = new PendingRequest();
pending.Callback = x =>
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
taskSource.SetResult((T)x);
};
pending.RequestType = type;
pending.ResponseType = responseType;
PendingRequests.Add(id, pending);
this.CityClient.Write(new DBRequestWrapperPDU()
2015-09-04 17:58:22 +01:00
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
Sender = new Sender
{
AriesID = "0",
MasterAccountID = "0",
},
SendingAvatarID = id,
Body = new cTSONetMessageStandard()
{
DatabaseType = type.GetRequestID(),
Parameter = parameter,
ComplexParameter = complexParameter
}
});
2015-09-04 17:58:22 +01:00
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
return (Task<T>)taskSource.Task;
}
2015-09-04 17:58:22 +01:00
}
public void MessageReceived(AriesClient client, object message)
{
if (!(message is DBRequestWrapperPDU))
{
2015-09-04 17:58:22 +01:00
return;
}
DBRequestWrapperPDU response = (DBRequestWrapperPDU)message;
if (response.Body is cTSONetMessageStandard)
{
2015-09-04 17:58:22 +01:00
var body = (cTSONetMessageStandard)response.Body;
var type = DBResponseTypeUtils.FromResponseID(body.DatabaseType.Value);
//TODO: I feel like a sequence id would be better for matching up request / responses, perhaps the old protocol has this and we've just missed it
var callback = PendingRequests[response.SendingAvatarID];//.FirstOrDefault(x => x.ResponseType == type);
if (callback != null)
{
PendingRequests.Remove(body.SendingAvatarID);
GameThread.NextUpdate(x =>
{
try
{
callback.Callback(body.ComplexParameter);
}
catch (Exception ex)
{
[Various] Cleanup update - ALL ANIMATIONS ARE NOW AT 1.2x SPEED. FreeSO was running these slightly too slow when compared to both TS1 and vanilla TSO. Interaction sounds should now correctly match up with animations. (PLEASE REPORT ANY ISSUES RELATED TO THIS IMMEDIATELY!) - Update Monogame: + fixes OpenGL audio bugs + mouse cursors now work in DirectX + we can add MSAA soon + probably a lot of other weird issues fixed - 3D City View now has touch screen controls. (desktop touch support via the "-touch" launch param) - When running, avatars now travel up stairs and get off chairs faster. - Avatars will now run to destinations further than 10 tiles away (unless "walk here" is queued, which will force walking) - Large scale program restructure. Please double check your NVIDIA and Firewall settings, since the application executable has changed! - Fixed purchase lot not telling you when your purchase was rejected because the lot name was already taken. - The purchasable outfit list is now ordered by price. - Secure trade's "grace period" is now less visually confusing. (disabled checkbox looked active) - Actually enforce Welcome Lot rules. (visitor skills disabled, except for newbies) - Welcome lot bonuses are now based on account age rather than sim age. I'd like to remind you that you're only allowed one account per person. - Smoke particles are no longer visible from floors above the current in 2D. - Fixed a weird bug with the 3D city transition and disabled surrounding lots. - Fixed a few crashes to do with the new loading stuff - Some more things
2018-06-09 17:55:56 +01:00
//LOG.Error(ex);
}
});
2015-09-04 17:58:22 +01:00
}
}
}
private uint NextMessageId()
{
lock (this)
{
var val = messageId;
messageId++;
return val;
}
}
}
2015-09-04 17:58:22 +01:00
public class PendingRequest
{
public DBRequestType RequestType;
public DBResponseType ResponseType;
public Callback<object> Callback;
}
}