public PatchAgent() { InitializeComponent(); Int32[] Widths = new Int32[(Int32)EField.Max] { 650, 50 }; AgentFields = new System.Windows.Forms.ColumnHeader[(Int32)EField.Max]; for (Int32 i = 0; i < (Int32)EField.Max; ++i) { AgentFields[i] = new System.Windows.Forms.ColumnHeader(); AgentFields[i].Text = ((EField)i).ToString(); AgentFields[i].Width = Widths[i]; } lvUpdateList.Columns.AddRange(AgentFields); //lvUpdateList.Location = new System.Drawing.Point(13, 39); //lvUpdateList.Size = new System.Drawing.Size(989, 677); lvUpdateList.UseCompatibleStateImageBehavior = false; lvUpdateList.FullRowSelect = true; lvUpdateList.ListViewItemSorter = new ListViewItemComparer(lvUpdateList.Sorting, 0); btnLogout.Enabled = false; btnSub.Enabled = false; btnAdd.Enabled = false; btnDel.Enabled = false; btnUpdate.Enabled = false; btnReset.Enabled = false; try { _Option = new COptionJson <SOption>("Option.ini", false); tbID.Text = _Option.Data.ID; tbPW.Text = _Option.Data.PW; _Net = new CAgent(_Option.Data.DataFileName, _Option.Data.DataPath, new CNamePort(_Option.Data.MasterNamePort), Link, LinkFail, UnLink, DataCallback); lbFullData.ColumnWidth = Width; foreach (var i in _Net.GetData().Files) { lbFullData.Items.Add(i.Key); } SetVersion(_Net.GetData().Version); timerNet.Enabled = true; } catch (Exception Exception_) { Log(Exception_.ToString()); } }
public void Proc() { for (var it = _Peers.Begin(); it;) { var itCheck = it; it.MoveNext(); var NetRet = itCheck.Data.Proc(); if (NetRet != ENetRet.Ok) { _Close(itCheck, NetRet); continue; } try { if (!itCheck.Data.Poll()) { continue; } while (true) { var RecvState = itCheck.Data.RecvedBegin(); if (RecvState == ERecvState.NoData) { break; } else if (RecvState == ERecvState.UserData) { if (!itCheck.Data.DoesWillClose()) { var Key = itCheck.Data.Key; try { _RecvFunc(Key, itCheck.Data.StreamRcv); } catch (Exception Exception_) { throw new ExceptionNet(ENetRet.ExceptionExternal, Exception_); } if (!_Peers.Get((Int32)Key.PeerNum)) { break; } } } itCheck.Data.RecvedEnd(); } } catch (ExceptionNet Exception_) { if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null) { throw Exception_.InnerException; } else { _Close(itCheck, Exception_.GetRet()); } } catch { _Close(itCheck, ENetRet.SocketError); } } }
public GameClientTest() { InitializeComponent(); try { var SetupJson = (JsonDataObject)JsonParser.Parse(File.ReadAllText("Option.ini")); _Auto = SetupJson["Auto"].GetBool(); ServerNo = SetupJson["ServerNo"].GetInt32(); var ServerInfo = ((JsonDataObject)(((JsonDataArray)SetupJson["Servers"])[ServerNo])); StartNum = ServerInfo["StartNum"].GetUInt32(); ClientCnt = ServerInfo["ClientCnt"].GetInt32(); if (ClientCnt <= 0) { throw new Exception("Invalid ClientCnt"); } DataPath = ServerInfo["DataPath"].GetString(); IP = ServerInfo["IP"].GetString(); Port = ServerInfo["Port"].GetUInt16(); ID = ServerInfo["ID"].GetString(); PW = ServerInfo["PW"].GetString(); TimerNet.Enabled = true; if (_Auto) { btnLoginUID.Enabled = false; } btnDisconnect.Enabled = false; _Net = new rso.game.CClient( Link, LinkFail, UnLink, Recv, LinkSoft, UnLinkSoft, Check, CheckFail, new SVersion(0, 0)); if (_Net == null) { return; } _Binder = new CClientBinder(_Net); _Clients = new SClient[ClientCnt]; for (TPeerCnt i = 0; i < ClientCnt; ++i) { _Clients[i] = new SClient(i); _Clients[i].Initialize(); } _Binder.AddSendProto <SGameProtoNetCs>((Int32)EProtoNetCs.GameProto); _Binder.AddRecvProto((Int32)EProtoNetSc.GameProto, GameProtoNetSc); TimerNet.Enabled = true; _Graphics = this.CreateGraphics(); } catch (Exception Exception_) { _Log(Exception_.ToString()); return; } }
public UInt64 Export <TProto>(string SheetName_, string TargetDir_, string[] ColumnNames_) where TProto : SProto, new() { try { try { _Worksheet = (Worksheet)_Workbook.Worksheets.get_Item(SheetName_); } catch { throw new Exception(string.Format("FileName[{0}] SheetName[{1}] does not exist at FileName[{2}]", _FileName, SheetName_, _FileName)); } object[,] _UsedRangeData = _Worksheet.UsedRange.Value; if (_UsedRangeData == null) { throw new Exception(string.Format("FileName[{0}] SheetName[{1}] is empty", _FileName, SheetName_)); } var RowCnt = _UsedRangeData.GetLength(0); if (RowCnt <= _RowOffset) { throw new Exception(string.Format("RowCnt[{0}] <= RowOffset[{0}]", RowCnt.ToString(), _RowOffset.ToString())); } var ColCnt = _UsedRangeData.GetLength(1); // Read Column Names //////////////////////////////////////// // 엑셀 컬럼을 순서대로 읽고 Value로 Index를 부여 var ColumnIndices = new Dictionary <string, Int32>(); for (Int32 c = 0; c < ColCnt; ++c) { string ColumnName = ""; if (_UsedRangeData[1 + _RowOffset, c + 1] != null) { ColumnName = _UsedRangeData[1 + _RowOffset, c + 1].ToString(); } if (ColumnName.Length == 0) { continue; } if (ColumnIndices.ContainsKey(ColumnName)) { throw new Exception(string.Format("Column is duplicated FileName[{0}] SheetName[{1}] ColumnNum[{2}] ColumnName[{3}]", _FileName, SheetName_, c.ToString(), ColumnName)); } ColumnIndices.Add(ColumnName, c); } var ExportExcelIndices = new List <Int32>(); // Export 할 컬럼의 엑셀에서의 인덱스 모음. foreach (var i in ColumnNames_) { if (!ColumnIndices.ContainsKey(i)) { throw new Exception(string.Format("Column can not be found FileName[{0}] SheetName[{1}] ColumnName[{2}]", _FileName, SheetName_, i)); } ExportExcelIndices.Add(ColumnIndices[i]); } var Proto = new TProto(); var SetFuncs = new List <TSetFunc>(); foreach (var i in Proto.StdName().Split(new char[] { ',' })) { switch (i) { case "bool": SetFuncs.Add((CStream Stream_, string Data_) => { try { Stream_.Push(bool.Parse(Data_) ? true : false); } catch { Stream_.Push(Int32.Parse(Data_) != 0 ? true : false); } }); break; case "int8": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(SByte.Parse(Data_)); }); break; case "uint8": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(Byte.Parse(Data_)); }); break; case "int16": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(Int16.Parse(Data_)); }); break; case "uint16": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(UInt16.Parse(Data_)); }); break; case "int32": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(Int32.Parse(Data_)); }); break; case "uint32": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(UInt32.Parse(Data_)); }); break; case "int64": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(Int64.Parse(Data_)); }); break; case "uint64": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(UInt64.Parse(Data_)); }); break; case "float": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(float.Parse(Data_)); }); break; case "double": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(double.Parse(Data_)); }); break; case "string": case "wstring": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(Data_); }); break; case "time_point": SetFuncs.Add((CStream Stream_, string Data_) => { Stream_.Push(new TimePoint(Int64.Parse(Data_))); }); break; default: // enum 으로 간주 SetFuncs.Add((CStream Stream_, string Data_) => { _EnumValue.PushToStream(i, Data_, Stream_); }); break; } } if (SetFuncs.Count != ExportExcelIndices.Count) { throw new Exception(string.Format("FileName[{0}] SheetName[{1}] Proto MemberCount[{2}] does not match export ColumnCount[{3}]", _FileName, SheetName_, SetFuncs.Count, ExportExcelIndices.Count)); } var DataStream = new CStream(); DataStream.Push(RowCnt - 1 - _RowOffset); for (Int32 r = 1 + _RowOffset; r < RowCnt; ++r) { for (Int32 i = 0; i < ExportExcelIndices.Count; ++i) { string CellData = ""; if (_UsedRangeData[r + 1, ExportExcelIndices[i] + 1] != null) { CellData = _UsedRangeData[r + 1, ExportExcelIndices[i] + 1].ToString(); } try { SetFuncs[i](DataStream, CellData); } catch (Exception Exception_) { throw new Exception(string.Format("Parse Error FileName[{0}] SheetName[{1}] Row[{2}] Column[{3}] Msg[{4}]", _FileName, SheetName_, r.ToString(), ExportExcelIndices[i].ToString(), Exception_.ToString())); } } } DataStream.SaveFile(Path.Combine(TargetDir_, SheetName_ + "." + _TargetExtension)); DisposeWorksheet(); return(DataStream.CheckSum()); } catch { Dispose(); throw; } }
public void ExportEnum(string SheetName_, string ColumnName_, string TargetDir_, string TargetFile_, string EnumFrameFormat_) { try { try { _Worksheet = (Worksheet)_Workbook.Worksheets.get_Item(SheetName_); } catch { throw new Exception(string.Format("FileName[{0}] SheetName[{1}] does not exist at FileName[{2}]", _FileName, SheetName_, _FileName)); } object[,] _UsedRangeData = _Worksheet.UsedRange.Value; if (_UsedRangeData == null) { throw new Exception(string.Format("FileName[{0}] SheetName[{1}] is empty", _FileName, SheetName_)); } var RowCnt = _UsedRangeData.GetLength(0); var ColCnt = _UsedRangeData.GetLength(1); // Read Column Names //////////////////////////////////////// // 엑셀 컬럼을 순서대로 읽고 Value로 Index를 부여 Int32 ColumnIndex = -1; for (Int32 c = 0; c < ColCnt; ++c) { if (_UsedRangeData[1, c + 1] != null) { if (_UsedRangeData[1, c + 1].ToString() == ColumnName_) { ColumnIndex = c; break; } } } if (ColumnIndex == -1) { throw new Exception(string.Format("Column is not found FileName[{0}] SheetName[{1}] ColumnName[{2}]", _FileName, SheetName_, ColumnName_)); } string Content = ""; for (Int32 r = 1; r < RowCnt; ++r) { string CellData = ""; if (_UsedRangeData[r + 1, ColumnIndex + 1] != null) { CellData = _UsedRangeData[r + 1, ColumnIndex + 1].ToString(); } try { if (r > 1) { Content += ",\n"; } Content += CellData; } catch (Exception Exception_) { throw new Exception(string.Format("Parse Error FileName[{0}] SheetName[{1}] Row[{2}] Column[{3}] Msg[{4}]", _FileName, SheetName_, r.ToString(), ColumnIndex.ToString(), Exception_.ToString())); } } Directory.CreateDirectory(TargetDir_); File.WriteAllText(Path.GetFullPath(Path.Combine(TargetDir_, TargetFile_)), string.Format(EnumFrameFormat_, Content)); DisposeWorksheet(); } catch { Dispose(); throw; } }
public new void Proc() { base.Proc(); for (var it = _Connectings.Begin(); it != _Connectings.End();) { var itCheck = it; it.MoveNext(); var itPeer = _PeersAndConnectings.Get(itCheck.Index); var PeerNum = itPeer.Data.PeerNum; var NamePort = itCheck.Data; _Connectings.Remove(itCheck); try { Socket Sock = null; AddressFamily[] AddressFamilies = { AddressFamily.InterNetwork, AddressFamily.InterNetworkV6 }; foreach (var i in NamePort.GetIPAddresses()) { if (i.AddressFamily != AddressFamily.InterNetwork) { continue; } foreach (var a in AddressFamilies) { Sock = new Socket(a, SocketType.Stream, ProtocolType.Tcp) { NoDelay = _NoDelay, SendBufferSize = _SendBuffSize, ReceiveBufferSize = _RecvBuffSize }; var RecvEvent = new SocketAsyncEventArgs(); RecvEvent.Completed += new EventHandler <SocketAsyncEventArgs>(_Worker); RecvEvent.UserToken = new _SConnectingInfo(itPeer.Data, Sock); RecvEvent.RemoteEndPoint = new IPEndPoint(i, NamePort.Port); bool ConnRet = false; try { ConnRet = Sock.ConnectAsync(RecvEvent); } catch { Sock = null; continue; } if (!ConnRet) { if (!RecvEvent.ConnectSocket.Connected) // Android(iOS는 미확인)에서 Wifi, Data 모두 끈 상태에서 여기에 들어오므로 여기서 연결여부 체크 { Sock = null; continue; } _Link(itPeer.Data, Sock, RecvEvent); } else { _ConnectTimeOut.Add((Int32)PeerNum, Sock); } break; // Success } if (Sock != null) { break; // Success } } if (Sock == null) { throw new Exception("Can not new Socket"); } } catch (ExceptionNet Exception_) { if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null) { throw Exception_.InnerException; } else { _PeersAndConnectings.Remove(itPeer); _LinkFail(PeerNum, Exception_.GetRet()); continue; } } catch { _PeersAndConnectings.Remove(itPeer); _LinkFail(PeerNum, ENetRet.SocketError); continue; } } for (var LFConnect = _Connects.GetPopBuf(); LFConnect != null; LFConnect = _Connects.GetPopBuf()) { var ConnectInfo = (_SConnectingInfo)LFConnect.Event.UserToken; var itPeer = _PeersAndConnectings.Get((Int32)ConnectInfo.Key.PeerNum); if (itPeer && itPeer.Data.Equals(ConnectInfo.Key)) { if (LFConnect.NetRet == ENetRet.Ok) { try { _Link(ConnectInfo.Key, ConnectInfo.socket, LFConnect.Event); } catch (ExceptionNet Exception_) { if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null) { throw Exception_.InnerException; } else { LFConnect.NetRet = Exception_.GetRet(); } } catch { LFConnect.NetRet = ENetRet.SystemError; } } if (LFConnect.NetRet != ENetRet.Ok) { _ConnectTimeOut.Remove(itPeer.Index); _PeersAndConnectings.Remove(itPeer); _LinkFail(ConnectInfo.Key.PeerNum, LFConnect.NetRet); } } _Connects.Pop(); } if (_ProcPeriod.CheckAndNextLoose()) { _ConnectTimeOut.Proc(); } }