Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Assets/Insight/InsightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Insight
{
public class InsightClient : InsightCommon
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(InsightClient));

public bool AutoReconnect = true;
protected int clientID = -1; //-1 = never connected, 0 = disconnected, 1 = connected
protected int connectionID = 0;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void StartInsight(string Address)
{
if(string.IsNullOrEmpty(Address))
{
logger.LogError("[InsightClient] - Address provided in StartInsight is Null or Empty. Not Starting.");
Debug.LogError("[InsightClient] - Address provided in StartInsight is Null or Empty. Not Starting.");
return;
}

Expand Down Expand Up @@ -92,7 +90,7 @@ private void CheckConnection()
{
if (!isConnected && (_reconnectTimer < Time.time))
{
logger.Log("[InsightClient] - Trying to reconnect...");
Debug.Log("[InsightClient] - Trying to reconnect...");
_reconnectTimer = Time.realtimeSinceStartup + ReconnectDelayInSeconds;
StartInsight();
}
Expand All @@ -113,7 +111,7 @@ public void Send<T>(T msg, CallbackHandler callback) where T : Message
{
if (!transport.ClientConnected())
{
logger.LogError("[InsightClient] - Client not connected!");
Debug.LogError("[InsightClient] - Client not connected!");
return;
}

Expand Down Expand Up @@ -146,10 +144,10 @@ void OnConnected()
{
if (insightNetworkConnection != null)
{
logger.Log("[InsightClient] - Connected to Insight Server");
Debug.Log("[InsightClient] - Connected to Insight Server");
connectState = ConnectState.Connected;
}
else logger.LogError("Skipped Connect message handling because m_Connection is null.");
else Debug.LogError("Skipped Connect message handling because m_Connection is null.");
}

void OnDisconnected()
Expand Down Expand Up @@ -185,31 +183,31 @@ protected void HandleBytes(ArraySegment<byte> data, int i)
else
{
//NOTE: this throws away the rest of the buffer. Need moar error codes
logger.LogError("Unknown message ID " + msgType);// + " connId:" + connectionId);
Debug.LogError("Unknown message ID " + msgType);// + " connId:" + connectionId);
}
}

void OnError(Exception exception)
{
// TODO Let's discuss how we will handle errors
logger.LogException(exception);
Debug.LogException(exception);
}

void OnApplicationQuit()
{
logger.Log("[InsightClient] Stopping Client");
Debug.Log("[InsightClient] Stopping Client");
StopInsight();
}

////------------Virtual Handlers-------------
public virtual void OnStartInsight()
{
logger.Log("[InsightClient] - Connecting to Insight Server: " + networkAddress);
Debug.Log("[InsightClient] - Connecting to Insight Server: " + networkAddress);
}

public virtual void OnStopInsight()
{
logger.Log("[InsightClient] - Disconnecting from Insight Server");
Debug.Log("[InsightClient] - Disconnecting from Insight Server");
}
}
}
6 changes: 2 additions & 4 deletions Assets/Insight/InsightCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public enum CallbackStatus : byte

public abstract class InsightCommon : MonoBehaviour
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(InsightCommon));

public bool DontDestroy = true; //Sets DontDestroyOnLoad for this object. Default to true. Can be disabled via Inspector or runtime code.
public bool AutoStart = true;
public string networkAddress = "localhost";
Expand Down Expand Up @@ -49,7 +47,7 @@ public virtual Transport transport
{
_transport = _transport ?? GetComponent<Transport>();
if (_transport == null)
logger.LogWarning("Insight has no Transport component. Networking won't work without a Transport");
Debug.LogWarning("Insight has no Transport component. Networking won't work without a Transport");
return _transport;
}
}
Expand All @@ -59,7 +57,7 @@ public void RegisterHandler<T>(InsightNetworkMessageDelegate handler)
int msgType = GetId<T>();
if (messageHandlers.ContainsKey(msgType))
{
logger.Log("NetworkConnection.RegisterHandler replacing " + msgType);
Debug.Log("NetworkConnection.RegisterHandler replacing " + msgType);
}
messageHandlers[msgType] = handler;
}
Expand Down
14 changes: 6 additions & 8 deletions Assets/Insight/InsightNetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Insight
{
public class InsightNetworkConnection : IDisposable
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(InsightNetworkConnection));

Dictionary<int, InsightNetworkMessageDelegate> m_MessageHandlers;

public int hostId = -1;
Expand Down Expand Up @@ -84,7 +82,7 @@ public bool InvokeHandler(short msgType, NetworkReader reader)
msgDelegate(message);
return true;
}
logger.LogError("NetworkConnection InvokeHandler no handler for " + msgType);
Debug.LogError("NetworkConnection InvokeHandler no handler for " + msgType);
return false;
}

Expand All @@ -103,7 +101,7 @@ public void RegisterHandler(short msgType, InsightNetworkMessageDelegate handler
{
if (m_MessageHandlers.ContainsKey(msgType))
{
logger.Log("NetworkConnection.RegisterHandler replacing " + msgType);
Debug.Log("NetworkConnection.RegisterHandler replacing " + msgType);
}
m_MessageHandlers[msgType] = handler;
}
Expand All @@ -125,14 +123,14 @@ protected virtual bool SendBytes(byte[] bytes)
//Currently no support for transport channels in Insight.
if (bytes.Length > GetActiveInsight().transport.GetMaxPacketSize(0))
{
logger.LogError("NetworkConnection:SendBytes cannot send packet larger than " + int.MaxValue + " bytes");
Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + int.MaxValue + " bytes");
return false;
}

if (bytes.Length == 0)
{
// zero length packets getting into the packet queues are bad.
logger.LogError("NetworkConnection:SendBytes cannot send zero bytes");
Debug.LogError("NetworkConnection:SendBytes cannot send zero bytes");
return false;
}

Expand All @@ -146,7 +144,7 @@ public virtual void TransportReceive(ArraySegment<byte> data)

if (GetActiveInsight().UnpackMessage(reader, out int msgType))
{
logger.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(data.Array, data.Offset, data.Count));
Debug.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(data.Array, data.Offset, data.Count));

int callbackId = reader.ReadInt32();

Expand All @@ -167,7 +165,7 @@ public virtual void TransportReceive(ArraySegment<byte> data)
else
{
//NOTE: this throws away the rest of the buffer. Need moar error codes
logger.LogError("Unknown message ID " + msgType + " connId:" + connectionId);
Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId);
}
}

Expand Down
26 changes: 12 additions & 14 deletions Assets/Insight/InsightServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Insight
{
public class InsightServer : InsightCommon
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(InsightServer));

protected int serverHostId = -1; //-1 = never connected, 0 = disconnected, 1 = connected
protected Dictionary<int, InsightNetworkConnection> connections = new Dictionary<int, InsightNetworkConnection>();
protected List<SendToAllFinishedCallbackData> sendToAllFinishedCallbacks = new List<SendToAllFinishedCallbackData>();
Expand Down Expand Up @@ -40,7 +38,7 @@ public virtual void Update()

public override void StartInsight()
{
logger.Log("[InsightServer] - Start");
Debug.Log("[InsightServer] - Start");
transport.ServerStart();
serverHostId = 0;

Expand All @@ -64,7 +62,7 @@ public override void StopInsight()

void HandleConnect(int connectionId)
{
logger.Log("[InsightServer] - Client connected connectionID: " + connectionId, this);
Debug.Log("[InsightServer] - Client connected connectionID: " + connectionId, this);

// get ip address from connection
string address = GetConnectionInfo(connectionId);
Expand All @@ -77,7 +75,7 @@ void HandleConnect(int connectionId)

void HandleDisconnect(int connectionId)
{
logger.Log("[InsightServer] - Client disconnected connectionID: " + connectionId, this);
Debug.Log("[InsightServer] - Client disconnected connectionID: " + connectionId, this);

InsightNetworkConnection conn;
if (connections.TryGetValue(connectionId, out conn))
Expand All @@ -95,7 +93,7 @@ void HandleData(int connectionId, ArraySegment<byte> data, int i)
InsightNetworkConnection insightNetworkConnection;
if (!connections.TryGetValue(connectionId, out insightNetworkConnection))
{
logger.LogError("HandleData: Unknown connectionId: " + connectionId, this);
Debug.LogError("HandleData: Unknown connectionId: " + connectionId, this);
return;
}

Expand All @@ -116,7 +114,7 @@ void HandleData(int connectionId, ArraySegment<byte> data, int i)
void OnError(int connectionId, Exception exception)
{
// TODO Let's discuss how we will handle errors
logger.LogException(exception);
Debug.LogException(exception);
}

public string GetConnectionInfo(int connectionId)
Expand Down Expand Up @@ -173,7 +171,7 @@ public bool SendToClient<T>(int connectionId, T msg, CallbackHandler callback =

return connections[connectionId].Send(writer.ToArray());
}
logger.LogError("Server.Send: not connected!", this);
Debug.LogError("Server.Send: not connected!", this);
return false;
}

Expand All @@ -189,7 +187,7 @@ public bool SendToClient(int connectionId, byte[] data)
transport.ServerSend(connectionId, 0, new ArraySegment<byte>(data));
return true;
}
logger.LogError("Server.Send: not connected!", this);
Debug.LogError("Server.Send: not connected!", this);
return false;
}

Expand All @@ -215,7 +213,7 @@ public bool SendToAll<T>(T msg, CallbackHandler callback, SendToAllFinishedCallb
}
return true;
}
logger.LogError("Server.Send: not connected!", this);
Debug.LogError("Server.Send: not connected!", this);
return false;
}

Expand All @@ -239,13 +237,13 @@ public bool SendToAll(byte[] bytes)
}
return true;
}
logger.LogError("Server.Send: not connected!", this);
Debug.LogError("Server.Send: not connected!", this);
return false;
}

void OnApplicationQuit()
{
logger.Log("[InsightServer] Stopping Server");
Debug.Log("[InsightServer] Stopping Server");
transport.ServerStop();
}

Expand Down Expand Up @@ -280,12 +278,12 @@ protected override void CheckCallbackTimeouts()
////----------virtual handlers--------------//
public virtual void OnStartInsight()
{
logger.Log("[InsightServer] - Server started listening");
Debug.Log("[InsightServer] - Server started listening");
}

public virtual void OnStopInsight()
{
logger.Log("[InsightServer] - Server stopping");
Debug.Log("[InsightServer] - Server stopping");
}
}
}
4 changes: 1 addition & 3 deletions Assets/Insight/Modules/Chat/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public class ChatClient : InsightModule
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(ChatClient));

InsightClient client;

//Used in Example Scene:
Expand All @@ -25,7 +23,7 @@ void RegisterHandlers()

public void HandleChatMsg(InsightNetworkMessage netMsg)
{
logger.Log("[InsightClient] - HandleChatMsg()");
Debug.Log("[InsightClient] - HandleChatMsg()");

ChatMsg message = netMsg.ReadMessage<ChatMsg>();

Expand Down
4 changes: 1 addition & 3 deletions Assets/Insight/Modules/Chat/ChatServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace Insight
{
public class ChatServer : InsightModule
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(ChatServer));

InsightServer server;
ServerAuthentication authModule;

Expand All @@ -33,7 +31,7 @@ void RegisterHandlers()

void HandleChatMsg(InsightNetworkMessage netMsg)
{
logger.Log("[ChatServer] - Received Chat Message.");
Debug.Log("[ChatServer] - Received Chat Message.");

ChatMsg message = netMsg.ReadMessage<ChatMsg>();

Expand Down
8 changes: 3 additions & 5 deletions Assets/Insight/Modules/GameManager/ClientGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Insight
{
public class ClientGameManager : InsightModule
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientGameManager));

InsightClient client;
Transport networkManagerTransport;

Expand All @@ -33,7 +31,7 @@ void HandleChangeServersMsg(InsightNetworkMessage netMsg)
{
ChangeServerMsg message = netMsg.ReadMessage<ChangeServerMsg>();

logger.Log("[InsightClient] - Connecting to GameServer: " + message.NetworkAddress + ":" + message.NetworkPort + "/" + message.SceneName);
Debug.Log("[InsightClient] - Connecting to GameServer: " + message.NetworkAddress + ":" + message.NetworkPort + "/" + message.SceneName);

if(networkManagerTransport.GetType().GetField("port") != null) {
networkManagerTransport.GetType().GetField("port").SetValue(networkManagerTransport, message.NetworkPort);
Expand All @@ -54,13 +52,13 @@ void HandleGameListMsg(InsightNetworkMessage netMsg)
{
GameListMsg message = netMsg.ReadMessage<GameListMsg>();

logger.Log("[InsightClient] - Received Games List");
Debug.Log("[InsightClient] - Received Games List");

gamesList.Clear();

foreach (GameContainer game in message.gamesArray)
{
logger.Log(game.SceneName);
Debug.Log(game.SceneName);

gamesList.Add(new GameContainer()
{
Expand Down
Loading