public static void Handle(Packet p, Presence pr, OyasumiDbContext context) { var ms = new MemoryStream(p.Data); using var reader = new SerializationReader(ms); var id = reader.ReadInt32(); var friend = PresenceManager.GetPresenceById(id); if (friend is null) { return; } var exists = context.Friends.FirstOrDefault(x => x.Friend2 == id); if (exists is not null) { return; } context.Friends.Add(new () { Friend1 = pr.Id, Friend2 = id }); Base.FriendCache[pr.Id].Add(friend.Id); context.SaveChanges(); }
public static void Handle(Packet p, Presence pr, OyasumiDbContext context) { var ms = new MemoryStream(p.Data); using var reader = new SerializationReader(ms); var id = reader.ReadInt32(); var friend = context.Friends.FirstOrDefault(x => x.Friend2 == id); if (friend is null) { return; } context.Friends.Remove(friend); Base.FriendCache.FirstOrDefault(x => x.Key == friend.Friend1).Value.Remove(friend.Friend2); context.SaveChanges(); }
public BanchoController(OyasumiDbContext context) =>
public LeaderboardController(OyasumiDbContext context) =>
public GeneralController(OyasumiDbContext context) =>
public RegistrationController(OyasumiDbContext context) { _context = context; }
public WebController(OyasumiDbContext context) =>
public UsersController(OyasumiDbContext context) =>
private static async Task Main(string[] args) { using var db = new OyasumiDbContext(); var user = new Users { Username = "******", Country = "RU", Password = "******" }; db.DBUsers.Add(user); await db.SaveChangesAsync(); var listener = new HttpListener(); listener.Prefixes.Add("http://+:5005/"); listener.Start(); if (!File.Exists("config.json")) { File.WriteAllText("config.json", JsonConvert.SerializeObject(new ConfigScheme { Database = "oyasumi", Username = "******", Password = "" })); } XConsole.PrintInfo("oyasumi!lazer - custom server for osu!lazer\n by Cherry, 2020"); while (true) { var context = await listener.GetContextAsync(); var request = context.Request; var response = context.Response; var headers = ""; response.KeepAlive = true; response.AddHeader("Keep-Alive", "timeout=5, max=100"); response.StatusCode = 200; response.AddHeader("Content-Type", "text/json; charset=UTF-8"); foreach (var k in request.Headers.AllKeys) { headers += k + ":" + " " + request.Headers[k] + "\n"; } XConsole.PrintInfo(headers); XConsole.PrintInfo(request.Url.AbsolutePath); if (request.HttpMethod == "POST") { var stream = request.InputStream; /*using var sr = new StreamReader(stream); * var body = sr.ReadToEnd(); */ switch (request.Url.AbsolutePath) { case "/oauth/token": var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false); var token = OAuth.Generate(parser.GetParameterValue("username"), parser.GetParameterValue("password")); await response.OutputStream.WriteAsync(Encoding.UTF8.GetBytes(token), 0, Encoding.UTF8.GetBytes(token).Length); break; case "/v2/me": break; default: XConsole.PrintInfo($"Unknown requested path: {request.Url.AbsolutePath}"); break; } response.Close(); } } }