25 using System.Collections.Generic;
28 using System.Runtime.InteropServices;
30 using System.Collections;
31 using System.Reflection;
39 static IntPtr m_ttsInst;
45 private void deleteMe()
47 if (m_ttsInst != IntPtr.Zero)
49 TTProDLL.TTS_CloseTeamTalk(m_ttsInst);
50 m_ttsInst = IntPtr.Zero;
80 return TTProDLL.TTS_SetEncryptionContext(m_ttsInst, ref szCertificateFile, ref szPrivateKeyFile);
102 return TTProDLL.TTS_SetEncryptionContextEx(m_ttsInst, ref lpEncryptionContext);
122 m_ttsInst = TTProDLL.TTS_InitTeamTalk();
150 return TTProDLL.TTS_RunEventLoop(m_ttsInst, pnWaitMs);
171 return TTProDLL.TTS_SetChannelFilesRoot(m_ttsInst, szFilesRoot, nMaxDiskUsage, nDefaultChannelQuota);
188 return TTProDLL.TTS_UpdateServer(m_ttsInst, ref lpServerProperties);
204 return TTProDLL.TTS_MakeChannel(m_ttsInst, ref lpChannel);
217 return TTProDLL.TTS_UpdateChannel(m_ttsInst, ref lpChannel);
229 return TTProDLL.TTS_RemoveChannel(m_ttsInst, nChannelID);
245 return TTProDLL.TTS_AddFileToChannel(m_ttsInst, ref szLocalFilePath, ref lpRemoteFile);
261 return TTProDLL.TTS_RemoveFileFromChannel(m_ttsInst, ref lpRemoteFile);
273 return TTProDLL.TTS_MoveUser(m_ttsInst, nUserID, ref lpChannel);
285 return TTProDLL.TTS_SendTextMessage(m_ttsInst, ref lpTextMessage);
301 public bool StartServer(
string szBindIPAddr,
int nTcpPort,
int nUdpPort,
bool bEncrypted)
303 return TTProDLL.TTS_StartServer(m_ttsInst, szBindIPAddr, nTcpPort, nUdpPort, bEncrypted);
318 public bool StartServerSysID(
string szBindIPAddr,
int nTcpPort,
int nUdpPort,
bool bEncrypted,
321 return TTProDLL.TTS_StartServerSysID(m_ttsInst, szBindIPAddr, nTcpPort, nUdpPort, bEncrypted, szSystemID);
329 return TTProDLL.TTS_StopServer(m_ttsInst);
332 public static string GetVersion() {
return Marshal.PtrToStringAuto(TTProDLL.TT_GetVersion()); }
333 class CallBack : IDisposable
335 private GCHandle hCallBack;
336 private IntPtr pCallFuncPointer;
340 this.lpCallback = lpCallback;
341 hCallBack = GCHandle.Alloc(lpCallback);
342 pCallFuncPointer = Marshal.GetFunctionPointerForDelegate(lpCallback);
343 GC.KeepAlive(lpCallback);
353 return pCallFuncPointer;
357 GC.SuppressFinalize(
this);
367 if (hCallBack.IsAllocated)
369 pCallFuncPointer = IntPtr.Zero;
374 return Object.Equals(lpCallback, x);
377 private delegate
bool DLL(IntPtr lpTTSInstance, IntPtr lpCallback,
int lpUserData,
bool bEnable);
378 private Dictionary<CallBack, DLL> Delegate2DLL =
new Dictionary<CallBack, DLL>();
379 private bool RegisterServerCallback(Delegate lpCallback,
int lpUserData,
bool bEnable)
381 CallBack callBack =
null;
383 string TTProDLL_Method =
"TTS_Register" + lpCallback.GetType().ToString().Split(
'+')[1];
384 MethodInfo method = typeof(TTProDLL).GetMethod(TTProDLL_Method);
385 DLL dg = (DLL)Delegate.CreateDelegate(typeof(DLL), method);
387 foreach (KeyValuePair<CallBack, DLL> cb
in Delegate2DLL)
389 if (cb.Key.Compare(lpCallback))
391 if (bEnable ==
true)
return true;
393 b = Delegate2DLL[callBack](m_ttsInst, callBack.GetFuncPointer(), 0, bEnable);
395 Delegate2DLL.Remove(callBack);
400 if (callBack ==
null && bEnable)
402 callBack =
new CallBack(lpCallback);
403 Delegate2DLL.Add(callBack, dg);
404 b = Delegate2DLL[callBack](m_ttsInst, callBack.GetFuncPointer(), 0, bEnable);
408 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
409 internal delegate
void UserLoggedInCallback(IntPtr lpTTSInstance, [In] IntPtr lpUserData, [In] ref User lpUser);
410 private event UserLoggedInCallback onUserLoggedInCallback;
411 internal event UserLoggedInCallback OnUserLoggedInCallBack
417 onUserLoggedInCallback += value;
418 RegisterServerCallback(value, 0,
true);
425 onUserLoggedInCallback -= value;
426 RegisterServerCallback(value, 0,
false);
432 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
433 internal delegate
void UserChangeNicknameCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In, Out] ref ClientErrorMsg lpClientErrorMsg, ref User lpUser, [In] [MarshalAs(UnmanagedType.LPWStr)]
string szNewNickname);
434 private event UserChangeNicknameCallback onUserChangeNicknameCallback;
435 internal event UserChangeNicknameCallback OnUserChangeNicknameCallback
441 onUserChangeNicknameCallback += value;
442 RegisterServerCallback(value, 0,
true);
449 onUserChangeNicknameCallback -= value;
450 RegisterServerCallback(value, 0,
false);
454 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
455 internal delegate
void UserChangeStatusCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In,Out] ref ClientErrorMsg lpClientErrorMsg, [In] ref User lpUser, [In] ref
int nNewStatusMode, [In] [MarshalAs(UnmanagedType.LPWStr)]
string szNewStatusMsg);
456 private event UserChangeStatusCallback onUserChangeStatusCallback;
457 internal event UserChangeStatusCallback OnUserChangeStatusCallback
463 onUserChangeStatusCallback += value;
464 RegisterServerCallback(value, 0,
true);
471 onUserChangeStatusCallback -= value;
472 RegisterServerCallback(value, 0,
false);
477 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
478 internal delegate
void UserLoginCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In, Out] ref ClientErrorMsg lpClientErrorMsg, ref User lpUser, [In, Out]ref UserAccount lpUserAccount);
479 object objectLock =
new Object();
480 private event UserLoginCallback onUserLoginCallback;
481 internal event UserLoginCallback OnUserLoginCallback
487 onUserLoginCallback += value;
488 RegisterServerCallback(value, 0,
true);
495 onUserLoginCallback -= value;
496 RegisterServerCallback(value, 0,
false);
500 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
501 internal delegate
void UserCreateUserAccountCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In, Out] ref ClientErrorMsg lpClientErrorMsg, ref User lpUser, [In, Out]ref UserAccount lpUserAccount);
502 private event UserCreateUserAccountCallback onUserCreateUserAccountCallback;
503 internal event UserCreateUserAccountCallback OnUserCreateUserAccountCallback
507 onUserCreateUserAccountCallback += value;
508 RegisterServerCallback(value, 0,
true);
512 onUserCreateUserAccountCallback -= value;
513 RegisterServerCallback(value, 0,
false);
516 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
517 internal delegate
void UserDeleteUserAccountCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In, Out] ref ClientErrorMsg lpClientErrorMsg, ref User lpUser, [In] [MarshalAs(UnmanagedType.LPWStr)]
string szUsername);
518 private event UserDeleteUserAccountCallback onUserDeleteUserAccountCallback;
519 internal event UserDeleteUserAccountCallback OnUserDeleteUserAccountCallback
523 onUserDeleteUserAccountCallback += value;
524 RegisterServerCallback(value, 0,
true);
528 onUserDeleteUserAccountCallback -= value;
529 RegisterServerCallback(value, 0,
false);
532 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
533 internal delegate
void UserAddServerBanCallback(IntPtr lpTTSInstance, IntPtr lpUserData, [In, Out] ref ClientErrorMsg lpClientErrorMsg, [In,Out] ref User lpBanner, [In,Out] ref User lpBanee);
534 private event UserAddServerBanCallback onUserAddServerBanCallback;
535 internal event UserAddServerBanCallback OnUserAddServerBanCallback
539 onUserAddServerBanCallback += value;
540 RegisterServerCallback(value, 0,
true);
544 onUserAddServerBanCallback -= value;
545 RegisterServerCallback(value, 0,
false);
548 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
549 internal delegate
void UserAddServerBanIPAddressCallback(IntPtr lpTTSInstance,
551 [In, Out] ref ClientErrorMsg lpClientErrorMsg,
552 [In] ref User lpBanner,
553 [In,Out] [MarshalAs(UnmanagedType.LPWStr)]
string szIPAddress);
554 private event UserAddServerBanIPAddressCallback onUserAddServerBanIPAddressCallback;
555 internal event UserAddServerBanIPAddressCallback OnUserAddServerBanIPAddressCallback
559 onUserAddServerBanIPAddressCallback += value;
560 RegisterServerCallback(value, 0,
true);
564 onUserAddServerBanIPAddressCallback -= value;
565 RegisterServerCallback(value, 0,
false);
568 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
569 internal delegate
void UserDeleteServerBanCallback(IntPtr lpTTSInstance,
571 [In, Out] ref ClientErrorMsg lpClientErrorMsg,
572 [In] ref User lpUser,
573 [In] [MarshalAs(UnmanagedType.LPWStr)]
string szIPAddress);
574 private event UserDeleteServerBanCallback onUserDeleteServerBanCallback;
575 internal event UserDeleteServerBanCallback OnUserDeleteServerBanCallback
579 onUserDeleteServerBanCallback += value;
580 RegisterServerCallback(value, 0,
true);
584 onUserDeleteServerBanCallback -= value;
585 RegisterServerCallback(value, 0,
false);
588 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
589 internal delegate
void UserConnectedCallback(IntPtr lpTTSInstance,
590 IntPtr lpUserData, [In] ref User lpUser);
591 private event UserConnectedCallback onUserConnectedCallback;
592 internal event UserConnectedCallback OnUserConnectedCallback
596 onUserConnectedCallback += value;
597 RegisterServerCallback(value, 0,
true);
601 onUserConnectedCallback -= value;
602 RegisterServerCallback(value, 0,
false);
605 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
606 internal delegate
void UserLoggedOutCallback(IntPtr lpTTSInstance,
607 IntPtr lpUserData, [In] ref User lpUser);
608 private event UserLoggedOutCallback onUserLoggedOutCallback;
609 internal event UserLoggedOutCallback OnUserLoggedOutCallback
613 onUserLoggedOutCallback += value;
614 RegisterServerCallback(value, 0,
true);
618 onUserLoggedOutCallback -= value;
619 RegisterServerCallback(value, 0,
false);
622 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
623 internal delegate
void UserDisconnectedCallback(IntPtr lpTTSInstance,
624 IntPtr lpUserData, [In] ref User lpUser);
625 private event UserDisconnectedCallback onUserDisconnectedCallback;
626 internal event UserDisconnectedCallback OnUserDisconnectedCallback
630 onUserDisconnectedCallback += value;
631 RegisterServerCallback(value, 0,
true);
635 onUserDisconnectedCallback -= value;
636 RegisterServerCallback(value, 0,
false);
639 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
640 internal delegate
void UserTimedoutCallback(IntPtr lpTTSInstance,
641 IntPtr lpUserData, [In] ref User lpUser);
642 private event UserTimedoutCallback onUserTimedoutCallback;
643 internal event UserTimedoutCallback OnUserTimedoutCallback
647 onUserTimedoutCallback += value;
648 RegisterServerCallback(value, 0,
true);
652 onUserTimedoutCallback -= value;
653 RegisterServerCallback(value, 0,
false);
656 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
657 internal delegate
void UserKickedCallback(IntPtr lpTTSInstance,
658 IntPtr lpUserData, IntPtr lpKicker,
659 [In] ref User lpKickee, [In] IntPtr lpChannel);
660 private event UserKickedCallback onUserKickedCallback;
661 internal event UserKickedCallback OnUserKickedCallback
665 onUserKickedCallback += value;
666 RegisterServerCallback(value, 0,
true);
670 onUserKickedCallback -= value;
671 RegisterServerCallback(value, 0,
false);
674 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
675 internal delegate
void UserBannedCallback(IntPtr lpTTSInstance,IntPtr lpUserData, [In,Out] ref User lpBanner,[In,Out] ref User lpBanee, IntPtr lpChannel);
676 private event UserBannedCallback onUserBannedCallback;
677 internal event UserBannedCallback OnUserBannedCallback
681 onUserBannedCallback += value;
682 RegisterServerCallback(value, 0,
true);
686 onUserBannedCallback -= value;
687 RegisterServerCallback(value, 0,
false);
690 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
691 internal delegate
void UserUnbannedCallback(IntPtr lpTTSInstance,
692 IntPtr lpUserData, [In] ref User lpUnbanner,
693 [In] [MarshalAs(UnmanagedType.LPWStr)]
string szIPAddress);
694 private event UserUnbannedCallback onUserUnbannedCallback;
695 internal event UserUnbannedCallback OnUserUnbannedCallback
699 onUserUnbannedCallback += value;
700 RegisterServerCallback(value, 0,
true);
704 onUserUnbannedCallback -= value;
705 RegisterServerCallback(value, 0,
false);
708 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
709 internal delegate
void UserUpdatedCallback(IntPtr lpTTSInstance,
710 IntPtr lpUserData, [In] ref User lpUser);
711 private event UserUpdatedCallback onUserUpdatedCallback;
712 internal event UserUpdatedCallback OnUserUpdatedCallback
716 onUserUpdatedCallback += value;
717 RegisterServerCallback(value, 0,
true);
721 onUserUpdatedCallback -= value;
722 RegisterServerCallback(value, 0,
false);
725 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
726 internal delegate
void UserJoinedChannelCallback(IntPtr lpTTSInstance,
727 IntPtr lpUserData, [In, Out] ref User lpUser,
728 [In,Out] ref Channel lpChannel);
729 private event UserJoinedChannelCallback onUserJoinedChannelCallback;
730 internal event UserJoinedChannelCallback OnUserJoinedChannelCallback
734 onUserJoinedChannelCallback += value;
735 RegisterServerCallback(value, 0,
true);
739 onUserJoinedChannelCallback -= value;
740 RegisterServerCallback(value, 0,
false);
743 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
744 internal delegate
void UserLeftChannelCallback(IntPtr lpTTSInstance,
745 IntPtr lpUserData, [In,Out] ref User lpUser,
746 [In,Out] ref Channel lpChannel);
747 private event UserLeftChannelCallback onUserLeftChannelCallback;
748 internal event UserLeftChannelCallback OnUserLeftChannelCallback
752 onUserLeftChannelCallback += value;
753 RegisterServerCallback(value, 0,
true);
757 onUserLeftChannelCallback -= value;
758 RegisterServerCallback(value, 0,
false);
761 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
762 internal delegate
void UserMovedCallback(IntPtr lpTTSInstance,
763 IntPtr lpUserData, [In,Out] ref User lpMover,
764 [In,Out] ref User lpMovee);
765 private event UserMovedCallback onUserMovedCallback;
766 internal event UserMovedCallback OnUserMovedCallback
770 onUserMovedCallback += value;
771 RegisterServerCallback(value, 0,
true);
775 onUserMovedCallback -= value;
776 RegisterServerCallback(value, 0,
false);
779 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
780 internal delegate
void UserTextMessageCallback(IntPtr lpTTSInstance,
781 IntPtr lpUserData, [In] ref User lpUser,
782 [In] ref TextMessage lpTextMessage);
783 private event UserTextMessageCallback onUserTextMessageCallback;
784 internal event UserTextMessageCallback OnUserTextMessageCallback
788 onUserTextMessageCallback += value;
789 RegisterServerCallback(value, 0,
true);
793 onUserTextMessageCallback -= value;
794 RegisterServerCallback(value, 0,
false);
797 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
798 internal delegate
void ChannelCreatedCallback(IntPtr lpTTSInstance,
799 IntPtr lpUserData,[In] ref Channel lpChannel,
801 private event ChannelCreatedCallback onChannelCreatedCallback;
802 internal event ChannelCreatedCallback OnChannelCreatedCallback
806 onChannelCreatedCallback += value;
807 RegisterServerCallback(value, 0,
true);
811 onChannelCreatedCallback -= value;
812 RegisterServerCallback(value, 0,
false);
815 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
816 internal delegate
void ChannelUpdatedCallback(IntPtr lpTTSInstance,
817 IntPtr lpUserData, [In] ref Channel lpChannel,
819 private event ChannelUpdatedCallback onChannelUpdatedCallback;
820 internal event ChannelUpdatedCallback OnChannelUpdatedCallback
824 onChannelUpdatedCallback += value;
825 RegisterServerCallback(value, 0,
true);
829 onChannelUpdatedCallback -= value;
830 RegisterServerCallback(value, 0,
false);
833 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
834 internal delegate
void ChannelRemovedCallback(IntPtr lpTTSInstance,
835 IntPtr lpUserData, [In] ref Channel lpChannel,
837 private event ChannelRemovedCallback onChannelRemovedCallback;
838 internal event ChannelRemovedCallback OnChannelRemovedCallback
842 onChannelRemovedCallback += value;
843 RegisterServerCallback(value, 0,
true);
847 onChannelRemovedCallback -= value;
848 RegisterServerCallback(value, 0,
false);
851 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
852 internal delegate
void FileUploadedCallback(IntPtr lpTTSInstance,
854 [In] ref RemoteFile lpRemoteFile,
855 [In] ref User lpUser);
856 private event FileUploadedCallback onFileUploadedCallback;
857 internal event FileUploadedCallback OnFileUploadedCallback
861 onFileUploadedCallback += value;
862 RegisterServerCallback(value, 0,
true);
866 onFileUploadedCallback -= value;
867 RegisterServerCallback(value, 0,
false);
870 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
871 internal delegate
void FileDownloadedCallback(IntPtr lpTTSInstance,
873 [In] ref RemoteFile lpRemoteFile,
874 [In] ref User lpUser);
875 private event FileDownloadedCallback onFileDownloadedCallback;
876 internal event FileDownloadedCallback OnFileDownloadedCallback
880 onFileDownloadedCallback += value;
881 RegisterServerCallback(value, 0,
true);
885 onFileDownloadedCallback -= value;
886 RegisterServerCallback(value, 0,
false);
889 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
890 internal delegate
void FileDeletedCallback(IntPtr lpTTSInstance,
892 [In] ref RemoteFile lpRemoteFile,
893 [In] ref User lpUser);
894 private event FileDeletedCallback onFileDeletedCallback;
895 internal event FileDeletedCallback OnFileDeletedCallback
899 onFileDeletedCallback += value;
900 RegisterServerCallback(value, 0,
true);
904 onFileDeletedCallback -= value;
905 RegisterServerCallback(value, 0,
false);
908 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
909 internal delegate
void ServerUpdatedCallback(IntPtr lpTTSInstance,
911 [In] ref ServerProperties lpServerProperties,
912 [In] ref User lpUser);
913 private event ServerUpdatedCallback onServerUpdatedCallback;
914 internal event ServerUpdatedCallback OnServerUpdatedCallback
918 onServerUpdatedCallback += value;
919 RegisterServerCallback(value, 0,
true);
923 onServerUpdatedCallback -= value;
924 RegisterServerCallback(value, 0,
false);
927 [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
928 internal delegate
void SaveServerConfigCallback(IntPtr lpTTSInstance,
931 private event SaveServerConfigCallback onSaveServerConfigCallback;
932 internal event SaveServerConfigCallback OnSaveServerConfigCallback
936 onSaveServerConfigCallback += value;
937 RegisterServerCallback(value, 0,
true);
941 onSaveServerConfigCallback -= value;
942 RegisterServerCallback(value, 0,
false);
Base class for BearWare.TeamTalk5Srv.
ClientError
Errors which can occur either as a result of client commands or as a result of internal errors.
void Close()
Close TeamTalk server instance.
static string GetVersion()
bool SetEncryptionContext(EncryptionContext lpEncryptionContext)
Set up encryption context for encrypted server.
CallBack(Delegate lpCallback)
ClientError UpdateServer([In] BearWare.ServerProperties lpServerProperties)
Set server properties.
TeamTalkSrvBase(Channel lpChannel)
bool RunEventLoop(int pnWaitMs)
Run the server's event loop.
virtual ClientError MakeChannel(BearWare.Channel lpChannel)
Make new channel.
void Dispose(bool disposing)
ClientError SetChannelFilesRoot(string szFilesRoot, Int64 nMaxDiskUsage, Int64 nDefaultChannelQuota)
The root folder of where users should upload files to.
ClientError SendTextMessage(BearWare.TextMessage lpTextMessage)
Send text message from server to clients.
bool StartServerSysID(string szBindIPAddr, int nTcpPort, int nUdpPort, bool bEncrypted, string szSystemID)
Same as StartServer() but with the option of specifying a system-ID.
TeamTalkSrvBase(Channel lpChannel, ServerProperties lpServerProperties)
ClientError RemoveChannel(int nChannelID)
Remove a channel.
ClientError AddFileToChannel(string szLocalFilePath, BearWare.RemoteFile lpRemoteFile)
Add a file to an existing channel.
ClientError RemoveFileFromChannel(RemoteFile lpRemoteFile)
Remove a file from a channel.
bool StopServer()
Stop server and drop all users.
ClientError MoveUser(int nUserID, BearWare.Channel lpChannel)
Move a user from one channel to another.
TeamTalkSrvBase()
Create new TeamTalk server instance.
bool StartServer(string szBindIPAddr, int nTcpPort, int nUdpPort, bool bEncrypted)
Start server on specified IP-address and ports.
ClientError UpdateChannel(Channel lpChannel)
Update an existing channel.
bool SetEncryptionContext(string szCertificateFile, string szPrivateKeyFile)
Set certificate and private key for encrypted server.
A struct containing the properties of a channel.
Configure peer verification for encrypted connection.
A struct containing the properties of a file in a BearWare.Channel.
A struct containing the properties of the server's settings.
A struct containing the properties of a text message sent by a user.