private void OnCS_IMC_Enter_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { if (_user.CastChannel != null) throw new AegisException(ResultCode.IMC_InChannel); Int32 channelNo = reqPacket.GetInt32(); _user.CastChannel = CastChannel.GetChannel(channelNo); _user.CastChannel.Enter(_user); { SecurePacket ntfPacket = new SecurePacket(Protocol.GetID("CS_IMC_EnteredUser_Ntf")); ntfPacket.PutInt32(ResultCode.Ok); ntfPacket.PutInt32(_user.UserNo); ntfPacket.PutStringAsUtf16(_user.Profile.Nickname); _user.CastChannel.Broadcast(ntfPacket, _user); } resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(_user.CastChannel.ChannelNo); resPacket.PutStringAsUtf16(_user.CastChannel.Name); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_Auth_LoginMember_Req(SecurePacketRequest reqPacket) { String uuid = reqPacket.GetStringFromUtf16(); String userId = reqPacket.GetStringFromUtf16(); String userPwd = reqPacket.GetStringFromUtf16(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); Services.Membership.Instance.LoginMember(uuid, userId, userPwd, (result, userNo) => { if (result == ResultCode.Ok) { _user = UserManagement.UserManager.Instance.GetUser(userNo); _user.LastSeqNo = reqPacket.SeqNo; _user.LoadFromDB(() => { _user.LoginCounter.OnLoggedIn(); resPacket.ResultCodeNo = result; resPacket.PutInt32(userNo); SendPacket(resPacket); }); } else { resPacket.ResultCodeNo = result; resPacket.PutInt32(userNo); SendPacket(resPacket); } }); }
private void OnCS_Profile_Text_SetData_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok); _user.TextBox.TextData = reqPacket.GetStringFromUtf16(); SendPacket(resPacket); }
private void OnCS_Profile_Text_GetData_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok, 65535); resPacket.PutStringAsUtf16(_user.TextBox.TextData); SendPacket(resPacket); }
private void OnCS_IMC_Create_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { if (_user.CastChannel != null) throw new AegisException(ResultCode.IMC_InChannel); String channelName = reqPacket.GetStringFromUtf16(); _user.CastChannel = CastChannel.NewChannel(channelName); _user.CastChannel.Enter(_user); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(_user.CastChannel.ChannelNo); resPacket.PutStringAsUtf16(_user.CastChannel.Name); } catch (AegisException e) { resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_CacheBox_SetValue_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok); String key = reqPacket.GetStringFromUtf16(); String value = reqPacket.GetStringFromUtf16(); Int32 durationMinutes = reqPacket.GetInt32(); Double expireTime = reqPacket.GetDouble(); try { if (durationMinutes == -1 && expireTime == -1) expireTime = -1; else if (durationMinutes >= 0) expireTime = DateTime.Now.AddMinutes(durationMinutes).ToOADate(); else expireTime = DateTime.FromOADate(expireTime).ToLocalTime().ToOADate(); CacheBox.Instance.Set(key, value, expireTime); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_Auth_RegisterGuest_Req(SecurePacketRequest reqPacket) { String uuid = reqPacket.GetStringFromUtf16(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); Services.Membership.Instance.RegisterGuest(uuid, (result) => { resPacket.ResultCodeNo = result; SendPacket(resPacket); }); }
private void OnCS_Profile_SetData_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok); _user.Profile.Nickname = reqPacket.GetStringFromUtf16(); _user.Profile.Level = reqPacket.GetInt16(); _user.Profile.Exp = reqPacket.GetInt16(); _user.Profile.UpdateToDB(); SendPacket(resPacket); }
public override StreamBuffer Clone() { SecurePacketResponse packet = new SecurePacketResponse(); packet.Write(Buffer); packet.ResetReadIndex(); packet.ResetWriteIndex(); packet.Read(ReadBytes); return packet; }
private void OnCS_CloudSheet_GetRecords_Req(SecurePacketRequest reqPacket) { String filename = reqPacket.GetStringFromUtf16(); String sheetName = reqPacket.GetStringFromUtf16(); UInt32 startRowNo = reqPacket.GetUInt32(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65535); try { resPacket.ResultCodeNo = ResultCode.Ok; Workbook workbook = Workbooks.GetWorkbook(filename); SheetData sheet = workbook.GetSheetData(sheetName); Int32 hasMoreIdx = resPacket.PutByte(0); Int32 rowCountIdx = resPacket.PutInt32(0); Int32 rowCount = 0; UInt32 lastRowIndex = 0; foreach (Record data in sheet.Records) { if (data == null || data.RowNo < startRowNo) continue; ++rowCount; lastRowIndex = data.RowNo; resPacket.PutUInt32(data.RowNo); foreach (String value in data.DataList) { if (value == null) resPacket.PutStringAsUtf16(""); else resPacket.PutStringAsUtf16(value.ToString()); } // #! 대략 이쯤... 패킷 크기를 초과하지 않도록 적당이 끊어준다. if (resPacket.WrittenBytes > 50000) break; } resPacket.OverwriteByte(hasMoreIdx, (Byte)(lastRowIndex < sheet.MaxRowNo ? 1 : 0)); resPacket.OverwriteInt32(rowCountIdx, rowCount); } catch (AegisException e) { Logger.Write(LogType.Err, 2, e.ToString()); resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_Profile_GetData_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok); resPacket.PutStringAsUtf16(_user.Profile.Nickname ?? ""); resPacket.PutInt16(_user.Profile.Level); resPacket.PutInt16(_user.Profile.Exp); resPacket.PutDouble(_user.LoginCounter.RegDate.ToOADate()); resPacket.PutDouble(_user.LoginCounter.LastLoginDate.ToOADate()); resPacket.PutByte(_user.LoginCounter.ContinuousCount); resPacket.PutByte(_user.LoginCounter.DailyCount); SendPacket(resPacket); }
private void OnCS_IMC_ChannelList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, ResultCode.Ok, 4096); Int32 count = 0, idxCount; idxCount = resPacket.PutInt32(count); foreach (var channel in CastChannel.Channels) { resPacket.PutInt32(channel.ChannelNo); resPacket.PutStringAsUtf16(channel.Name); ++count; } resPacket.OverwriteInt32(idxCount, count); SendPacket(resPacket); }
private void OnCS_CacheBox_GetValue_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65535); String key = reqPacket.GetStringFromUtf16(); try { String value; Int32 durationMunites; CacheBox.Instance.Get(key, out value, out durationMunites); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutStringAsUtf16(value); resPacket.PutInt32(durationMunites); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_CloudSheet_GetSheetList_Req(SecurePacketRequest reqPacket) { String filename = reqPacket.GetStringFromUtf16(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65535); try { Workbook workbook = Workbooks.GetWorkbook(filename); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(workbook.Items.Count()); foreach (SheetData sheet in workbook.Items.Select(v => v.Value)) { // Sheet information resPacket.PutStringAsUtf16(sheet.Name); resPacket.PutInt32(sheet.Records.Count()); resPacket.PutInt32(sheet.Fields.Count()); // Field information foreach (var fieldInfo in sheet.Fields) { resPacket.PutInt32((Int32)fieldInfo.DataType); resPacket.PutStringAsUtf16(fieldInfo.Name); } } } catch (AegisException e) { Logger.Write(LogType.Err, 2, e.ToString()); resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_IMC_Leave_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { if (_user.CastChannel == null) throw new AegisException(ResultCode.IMC_NotInChannel); _user.CastChannel.Leave(_user); { SecurePacket ntfPacket = new SecurePacket(Protocol.GetID("CS_IMC_LeavedUser_Ntf")); ntfPacket.PutInt32(ResultCode.Ok); ntfPacket.PutInt32(_user.UserNo); _user.CastChannel.Broadcast(ntfPacket, _user); } _user.CastChannel = null; resPacket.ResultCodeNo = ResultCode.Ok; } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_IMC_UserList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 4096); try { Int32 count = 0, idxCount; resPacket.ResultCodeNo = ResultCode.Ok; idxCount = resPacket.PutInt32(count); foreach (var user in _user.CastChannel.Users) { resPacket.PutInt32(user.UserNo); resPacket.PutStringAsUtf16(user.Profile.Nickname); ++count; } resPacket.OverwriteInt32(idxCount, count); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_IMC_SendMessage_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); Int32 targetUserNo = reqPacket.GetInt32(); if (_user.CastChannel == null) { resPacket.ResultCodeNo = ResultCode.IMC_NotInChannel; SendPacket(resPacket); return; } try { SecurePacket ntfPacket = new SecurePacket(Protocol.GetID("CS_IMC_Message_Ntf"), (UInt16)reqPacket.ReadableSize); ntfPacket.PutInt32(ResultCode.Ok); ntfPacket.PutInt32(_user.UserNo); ntfPacket.Write(reqPacket.Buffer, reqPacket.ReadBytes, reqPacket.ReadableSize); if (targetUserNo != 0) { User targetUser = _user.CastChannel.GetUser(targetUserNo); targetUser.SendPacket(ntfPacket); } else _user.CastChannel.Broadcast(ntfPacket); resPacket.ResultCodeNo = ResultCode.Ok; } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }