public void TestGetters() { Assert.AreEqual(5.0, _biDictionary.GetByFirst(10)); Assert.AreEqual(int.MaxValue, _biDictionary.GetBySecond(double.MinValue)); Assert.AreEqual(default(double), _biDictionary.GetByFirst(1)); Assert.AreEqual(default(int), _biDictionary.GetBySecond(1.0)); }
public void DirectRemoveClient(int clientID) { if (!isServer) { return; } OnServerDisconnected?.Invoke(connectedDirectClients.GetByFirst(clientID)); connectedDirectClients.Remove(clientID); }
public void AddAudit(DbCommand cmd, string environmentDotStackTrace) { //is it a novel origin if (!DictionaryOfQueries.Firsts.Contains(environmentDotStackTrace)) { DictionaryOfQueries.Add(environmentDotStackTrace, new QueryPerformed(cmd.CommandText)); } var query = DictionaryOfQueries.GetByFirst(environmentDotStackTrace); query.IncrementSeenCount(); }
public static int GetOpcode(Opcode opcodeId, Direction direction) { switch (direction) { case Direction.ClientToServer: return(ClientDict.GetByFirst(opcodeId)); case Direction.ServerToClient: return(ServerDict.GetByFirst(opcodeId)); case Direction.Bidirectional: return(MiscDict.GetByFirst(opcodeId)); } return(0); }
public static int GetOpcode(Opcode opcode) { return(Dict.GetByFirst(opcode)); }
private void Client_MessageReceived(object sender, DarkRift.Client.MessageReceivedEventArgs e) { try { using (Message message = e.GetMessage()) using (DarkRiftReader reader = message.GetReader()) { OpCodes opCode = (OpCodes)message.Tag; switch (opCode) { case OpCodes.ServerConnectionData: string serverIP = reader.ReadString(); if (directConnectModule == null) { directConnectAddress = ""; return; } directConnectAddress = serverIP; if (showDebugLogs) { Debug.Log("Received direct connect info from server."); } break; case OpCodes.Authenticated: isAuthenticated = true; if (showDebugLogs) { Debug.Log("Authenticated with server."); } break; case OpCodes.AuthenticationRequest: using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(relayPassword); using (Message sendAuthenticationResponse = Message.Create((ushort)OpCodes.AuthenticationResponse, writer)) drClient.Client.SendMessage(sendAuthenticationResponse, SendMode.Reliable); } if (showDebugLogs) { Debug.Log("Server requested authentication key."); } break; case OpCodes.GetData: int dataLength = reader.ReadInt32(); byte[] receivedData = new byte[dataLength]; System.Buffer.BlockCopy(reader.ReadBytes(), 0, receivedData, 0, dataLength); if (isServer) { OnServerDataReceived?.Invoke(connectedRelayClients.GetByFirst(reader.ReadUInt16()), new ArraySegment <byte>(receivedData), e.SendMode == SendMode.Unreliable ? 1 : 0); } if (isClient) { OnClientDataReceived?.Invoke(new ArraySegment <byte>(receivedData), e.SendMode == SendMode.Unreliable ? 1 : 0); } break; case OpCodes.ServerLeft: if (isClient) { isClient = false; OnClientDisconnected?.Invoke(); } break; case OpCodes.PlayerDisconnected: if (isServer) { ushort user = reader.ReadUInt16(); OnServerDisconnected?.Invoke(connectedRelayClients.GetByFirst(user)); connectedRelayClients.Remove(user); if (showDebugLogs) { Debug.Log($"Client {user} left room."); } } break; case OpCodes.RoomCreated: serverID = reader.ReadUInt16(); isConnected = true; if (showDebugLogs) { Debug.Log("Server Created on relay."); } break; case OpCodes.ServerJoined: ushort clientID = reader.ReadUInt16(); if (isClient) { isConnected = true; OnClientConnected?.Invoke(); if (showDebugLogs) { Debug.Log("Successfully joined server."); } } if (isServer) { connectedRelayClients.Add(clientID, currentMemberID); OnServerConnected?.Invoke(currentMemberID); currentMemberID++; if (showDebugLogs) { Debug.Log($"Client {clientID} joined the server."); } } break; case OpCodes.ServerListResponse: int serverListCount = reader.ReadInt32(); relayServerList.Clear(); for (int i = 0; i < serverListCount; i++) { relayServerList.Add(new RelayServerInfo() { serverName = reader.ReadString(), currentPlayers = reader.ReadInt32(), maxPlayers = reader.ReadInt32(), serverID = reader.ReadUInt16(), serverData = reader.ReadString() }); } serverListUpdated?.Invoke(); if (showDebugLogs) { Debug.Log("Received Server List."); } break; } } } catch { // Server shouldnt send messed up data but we do have an unreliable channel, so eh. } }
public static string getById(int id) { return(Dictionary.GetByFirst(id)); }