초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace GameServer;
public class BeaconShopMongoDoc
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } = null!;
public string ItemGuid { get; set; } = null!;
public int TagId { get; set; } = 0;
public string BeaconGuid { get; set; } = null!;
public string BeaconNickName { get; set; } = null!;
public string BeaconTitle { get; set; } = string.Empty;
public int BeaconBodyItemMetaId { get; set; } = 0;
public double PriceForUnit { get; set; } = 0;
public int Amount { get; set; } = 0;
public string OwnerGuid { get; set; } = null!;
public string OwnerNickName { get; set; } = null!;
public string BeaconMyHomeGuid { get; set; } = null!;
[BsonRequired]
public DateTime SellingFinishTime { get; set; } = new();
}

View File

@@ -0,0 +1,134 @@

using MongoDB.Driver;
using ServerBase;
using ServerCore;
using BEACON_GUID = System.String;
using META_ID = System.UInt32;
using USER_GUID = System.String;
using ITEM_GUID = System.String;
namespace GameServer;
public class BeaconShopRepository : MongoDbRepository<BeaconShopMongoDoc>
{
private const string CollectionName = "BeaconShop";
public BeaconShopRepository(IMongoClient mongoClient, MongoDbConf settings) :
base(mongoClient, settings.DatabaseName, CollectionName)
{
}
public async Task<(Result, List<BeaconShopMongoDoc>?)> get(int tagId)
{
var result = new Result();
var err_msg = string.Empty;
var builder = Builders<BeaconShopMongoDoc>.Filter;
var filter = builder.Eq(x => x.TagId, tagId);
try
{
var findData = await m_collection.FindAsync(filter);
return (result, findData.ToList());
}
catch (Exception ex)
{
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
result.setFail(ServerErrorCode.BeaconShopFailedGetBoardItem, err_msg);
return (result, null);
}
}
public async Task<Result> insert(BeaconShopMongoDoc beaconShopEntity)
{
var result = new Result();
var err_msg = string.Empty;
try
{
await m_collection.InsertOneAsync(beaconShopEntity);
}
catch (Exception ex)
{
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
result.setFail(ServerErrorCode.BeaconShopFailedRegisterBoard, err_msg);
Log.getLogger().error(err_msg);
return result;
}
return result;
}
public async Task<(Result, BeaconShopMongoDoc?)> updateAmount(string id, int amount)
{
var result = new Result();
var err_msg = string.Empty;
try
{
var filter = Builders<BeaconShopMongoDoc>.Filter
.Eq(x => x.ItemGuid, id);
var update = Builders<BeaconShopMongoDoc>.Update
.Inc(x => x.Amount, amount);
var options = new FindOneAndUpdateOptions<BeaconShopMongoDoc>
{
ReturnDocument = ReturnDocument.After,
};
var updated = await m_collection.FindOneAndUpdateAsync(filter, update, options);
if (updated == null)
{
err_msg = $"MongoDB is already empty. Error";
result.setFail(ServerErrorCode.BeaconShopFailedToFindOrUpdate, err_msg);
return (result, null);
}
if (updated.Amount == 0)
{
return (await delete(id), updated);
}
return (result, updated);
}
catch (Exception ex)
{
err_msg = $"MongoDB Write Exception Error: {ex.Message}";
result.setFail(ServerErrorCode.BeaconShopDbException, err_msg);
return (result, null);
}
}
public async Task<Result> delete(ITEM_GUID item_guid)
{
var result = new Result();
var err_msg = string.Empty;
var builder = Builders<BeaconShopMongoDoc>.Filter;
var filter = builder.Eq(x => x.ItemGuid, item_guid);
try
{
var db_result = await m_collection.DeleteOneAsync(filter);
if (db_result.DeletedCount == 0)
{
result.setFail(ServerErrorCode.BeaconShopNotFoundItemFromBoard, err_msg);
return result;
}
}
catch (Exception ex)
{
err_msg = $"MongoDB Delete Exception Error : {ex.Message}";
result.setFail(ServerErrorCode.BeaconShopFailedDeleteBoard, err_msg);
return result;
}
return result;
}
}