void CloseSocket(SocketAsyncEventArgs e) { try { var client = (TCPClient)e.UserToken; lock (_clients) { _clients.Remove(client.ConnectionID); } MessageData message = new MessageData("none"); message["source"] = client.socket.RemoteEndPoint; message["cid"] = client.ConnectionID; try { DWMatch.Net_TcpDisconnected(message); DWGroups.Net_TcpDisconnected(message); DWRouter.Net_TcpDisconnected(message); } catch (Exception ex) { Log.Error(ex.ToString()); } try { client.socket.Shutdown(SocketShutdown.Both); } catch { } client.socket.Close(); } catch (Exception ex) { Log.Error(ex.ToString()); } }
private void redirectPacket(MessageData data) { data.Arguments["handled"] = false; var type = data.Get <int>("type"); var crypt = data.Get <bool>("crypt"); bool routed = false; try { if (!crypt && (type == 28 || type == 12 || type == 26)) { DWAuther.DW_PacketReceived(data); routed = true; //Log.Debug("got auth packet"); } if (crypt && type == 28) { DWGroups.DW_PacketReceived(data); routed = true; } if (type == 7) { DWLobby.DW_PacketReceived(data); routed = true; //Log.Debug("got lobby packet"); } if (type == 6) { DWMessaging.DW_PacketReceived(data); routed = true; //Log.Debug("got service packet"); } if (type == 21) { DWMatch.DW_PacketReceived(data); routed = true; //Log.Debug("got match packet"); } if ((type == 10) || (type == 18) || (type == 23) || (type == 8 || type == 50 || type == 4 || type == 58)) { DWStorage.DW_PacketReceived(data); routed = true; //Log.Debug("got storage packet"); } if (type == 12 && crypt) { DWTitles.DW_PacketReceived(data); routed = true; //Log.Debug("got Title packet"); } if (type == 8) { DWProfiles.DW_PacketReceived(data); routed = true; } if (type == 27) { DWDML.DW_PacketReceived(data); } if (type == 67) { DWEventLog.DW_PacketReceived(data); } } catch (Exception e) { Log.Error("Exception: " + e.ToString()); } /*if(routed == false) * { * Log.Debug("UNHANDLED PACKET: " + type); * }*/ try { if (crypt && !data.Get <bool>("handled")) { DWRouter.Unknown(data, DWRouter.GetMessage(data)); } } catch { Log.Error("UNKNOWN FAILED, THIS CONNECTION CAN BE CONSIDERED DEAD."); // disconnect to prevent pollution of system TCPHandler.ForceDisconnect(data); } }
static void Main(string[] args) { Log.Initialize("DWServer.log", LogLevel.Data | LogLevel.Info | LogLevel.Error | LogLevel.Debug | LogLevel.Verbose, true); Log.Info("Starting DW server"); var game = (args.Length == 1) ? args[0] : "t5"; if (game == "t5") { Game = TitleID.T5; } else if (game == "iw5") { Game = TitleID.IW5; } /* * TCPHandler ipServer = new TCPHandler(3074); * ipServer.Start(); * TCPHandler ipServer3 = new TCPHandler(3077); * ipServer3.Start(); */ Database.Initialize(); DWRouter.OnStart(); //TCPHandler.OnStart(); var handler = new TCPHandler(); //default: 3074, deviain handler.Start((game == "t5") ? 3074 : 3078); Heatmap.StartThread(); HttpHandler.Start(); /*MessageData server2 = new MessageData("none"); * server2.Arguments["name"] = "demonware2"; * server2.Arguments["port"] = (int)3077; * TCPHandler.Net_TcpListen("none", server2);*/ new Thread(() => { while (true) { Thread.Sleep(30000); try { DWMatch.CleanSessions(); } catch (Exception e) { Log.Error(e.ToString()); } } }).Start(); new Thread(() => { while (true) { Thread.Sleep(30000);//30000 try { DWGroups.updateCache(); } catch (Exception e) { Log.Error(e.ToString()); } } }).Start(); while (true) { try { Log.WriteAway(); } catch (Exception e) { Log.Error(e.ToString()); } Thread.Sleep(1000); } }