Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
50 changed files
with
3,654 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| using System; | ||
| using System.CodeDom; | ||
| using System.Collections.Generic; | ||
| using System.Dynamic; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using Rice.Game; | ||
| using Rice.Server.Core; | ||
|
|
||
| namespace Rice | ||
| { | ||
| public class Admin | ||
| { | ||
| private static HttpListener listener; | ||
|
|
||
| public static void Initialize(Config config) | ||
| { | ||
| listener = new HttpListener(); | ||
| listener.Prefixes.Add("http://localhost:8088/"); | ||
| listener.Start(); | ||
|
|
||
| listener.BeginGetContext(onGetContext, null); | ||
| } | ||
|
|
||
| private static void onGetContext(IAsyncResult result) | ||
| { | ||
| var ctx = listener.EndGetContext(result); | ||
| switch (ctx.Request.RawUrl) | ||
| { | ||
| case "/status": | ||
| case "/status/": | ||
| onStatus(ctx); | ||
| break; | ||
|
|
||
| case "/favicon.ico": | ||
| break; | ||
|
|
||
| default: | ||
| Log.WriteLine("Unhandled JSON API request: {0}", ctx.Request.RawUrl); | ||
| writeJsonResp(new { status = "error", error = "Invalid API call." }, ctx); | ||
| break; | ||
| } | ||
| listener.BeginGetContext(onGetContext, null); | ||
| } | ||
|
|
||
| private static void writeJsonResp(object obj, HttpListenerContext ctx) | ||
| { | ||
| var resp = ctx.Response; | ||
| string str = JsonConvert.SerializeObject(obj); | ||
| byte[] strBytes = Encoding.UTF8.GetBytes(str); | ||
|
|
||
| resp.ContentLength64 = strBytes.Length; | ||
| resp.OutputStream.Write(strBytes, 0, strBytes.Length); | ||
| resp.OutputStream.Close(); | ||
| } | ||
|
|
||
| private static void onStatus(HttpListenerContext ctx) | ||
| { | ||
| dynamic status = new ExpandoObject(); | ||
| status.status = "ok"; | ||
| status.playercount = RiceServer.GetPlayers().Length; | ||
|
|
||
| var servers = new [] {RiceServer.Auth, RiceServer.Lobby, RiceServer.Game, RiceServer.Area, RiceServer.Ranking}; | ||
| status.servers = servers | ||
| .Select(server => new | ||
| { | ||
| name = server.Name, | ||
| clientcount = server.GetClients().Length | ||
| }); | ||
|
|
||
| status.areas = RiceServer.GetAreas() | ||
| .Where(a => a.GetPlayerCount() > 0) | ||
| .Select(area => new | ||
| { | ||
| id = area.ID, | ||
| playercount = area.GetPlayerCount(), | ||
| players = area.GetPlayers() | ||
| .Select(p => new | ||
| { | ||
| name = p.ActiveCharacter.Name, | ||
| level = p.ActiveCharacter.Level | ||
| }) | ||
| }); | ||
|
|
||
| writeJsonResp(status, ctx); | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <startup> | ||
|
|
||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> | ||
| </configuration> | ||
| <configSections> | ||
| <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> | ||
| <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | ||
| </configSections> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> | ||
| </startup> | ||
| <entityFramework> | ||
| <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> | ||
| <parameters> | ||
| <parameter value="v13.0" /> | ||
| </parameters> | ||
| </defaultConnectionFactory> | ||
| <providers> | ||
| <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> | ||
| <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"> | ||
| </provider></providers> | ||
| </entityFramework> | ||
| <system.data> | ||
| <DbProviderFactories> | ||
| <remove invariant="MySql.Data.MySqlClient" /> | ||
| <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> | ||
| </DbProviderFactories> | ||
| </system.data></configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Rice.Server.Core; | ||
|
|
||
| namespace Rice.Game | ||
| { | ||
| public class Area | ||
| { | ||
| public int ID; | ||
| private List<Player> players; | ||
|
|
||
| public Area(int id) | ||
| { | ||
| ID = id; | ||
| players = new List<Player>(); | ||
| } | ||
|
|
||
| public void AddPlayer(Player player) | ||
| { | ||
| if (players.Contains(player)) | ||
| { | ||
| Log.WriteLine("Weird: Player already in area."); | ||
| RemovePlayer(player); | ||
| } | ||
| players.Add(player); | ||
| player.ActiveCharacter.Area = this; | ||
| Log.WriteLine("Added player {0} to area {1}.", player.ActiveCharacter.Name, ID); | ||
| } | ||
|
|
||
| public void RemovePlayer(Player player) | ||
| { | ||
| players.Remove(player); | ||
| player.ActiveCharacter.Area = null; | ||
| Log.WriteLine("Removed player {0} from area {1}.", player.ActiveCharacter.Name, ID); | ||
| } | ||
|
|
||
| public Player[] GetPlayers() | ||
| { | ||
| return players.ToArray(); | ||
| } | ||
|
|
||
| public int GetPlayerCount() | ||
| { | ||
| return players.Count; | ||
| } | ||
|
|
||
| public void BroadcastMovement(Player player, byte[] movement) // byte[] temporarily | ||
| { | ||
| var move = new RicePacket(0x21D); // 114 total length | ||
| move.Writer.Write(player.ActiveCharacter.CarSerial); | ||
| move.Writer.Write(movement); | ||
|
|
||
| foreach (Player areaPlayer in players) | ||
| { | ||
| if (areaPlayer != player) | ||
| areaPlayer.AreaClient.Send(move); | ||
| } | ||
| } | ||
|
|
||
| public void Broadcast(RicePacket packet, RiceClient exclude = null) | ||
| { | ||
| foreach (var player in GetPlayers()) | ||
| { | ||
| var client = player.AreaClient; | ||
|
|
||
| if (exclude == null || client != exclude) | ||
| client.Send(packet); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.