Cuberite
A lightweight, fast and extensible game server for Minecraft
ManualBindings_RankManager.cpp
Go to the documentation of this file.
1 
2 // ManualBindings_RankManager.cpp
3 
4 // Implements the cRankManager Lua bindings
5 
6 #include "Globals.h"
7 #include "ManualBindings.h"
8 #include "tolua++/include/tolua++.h"
9 #include "LuaState.h"
10 #include "../Root.h"
11 #include "../UUID.h"
12 
13 
14 
15 
16 
18 static int tolua_cRankManager_AddGroup(lua_State * L)
19 {
20  // Function signature:
21  // cRankManager:AddGroup(GroupName)
22 
23  cLuaState S(L);
24  if (
25  !S.CheckParamUserTable(1, "cRankManager") ||
26  !S.CheckParamString(2) ||
27  !S.CheckParamEnd(3)
28  )
29  {
30  return 0;
31  }
32 
33  // Read the params:
34  AString GroupName;
35  S.GetStackValue(2, GroupName);
36 
37  // Add the group:
38  cRoot::Get()->GetRankManager()->AddGroup(GroupName);
39  return 0;
40 }
41 
42 
43 
44 
45 
47 static int tolua_cRankManager_AddGroupToRank(lua_State * L)
48 {
49  // Function signature:
50  // cRankManager:AddGroupToRank(GroupName, RankName) -> bool
51 
52  cLuaState S(L);
53  if (
54  !S.CheckParamUserTable(1, "cRankManager") ||
55  !S.CheckParamString(2, 3) ||
56  !S.CheckParamEnd(4)
57  )
58  {
59  return 0;
60  }
61 
62  // Read the params:
63  AString GroupName, RankName;
64  S.GetStackValues(2, GroupName, RankName);
65 
66  // Add the group to the rank:
67  S.Push(cRoot::Get()->GetRankManager()->AddGroupToRank(GroupName, RankName));
68  return 1;
69 }
70 
71 
72 
73 
74 
76 static int tolua_cRankManager_AddPermissionToGroup(lua_State * L)
77 {
78  // Function signature:
79  // cRankManager:AddPermissionToGroup(Permission, GroupName) -> bool
80 
81  cLuaState S(L);
82  if (
83  !S.CheckParamUserTable(1, "cRankManager") ||
84  !S.CheckParamString(2, 3) ||
85  !S.CheckParamEnd(4)
86  )
87  {
88  return 0;
89  }
90 
91  // Read the params:
92  AString GroupName, Permission;
93  S.GetStackValues(2, Permission, GroupName);
94 
95  // Add the group to the rank:
96  S.Push(cRoot::Get()->GetRankManager()->AddPermissionToGroup(Permission, GroupName));
97  return 1;
98 }
99 
100 
101 
102 
103 
105 static int tolua_cRankManager_AddRank(lua_State * L)
106 {
107  // Function signature:
108  // cRankManager:AddRank(RankName)
109 
110  cLuaState S(L);
111  if (
112  !S.CheckParamUserTable(1, "cRankManager") ||
113  !S.CheckParamString(2, 5) ||
114  !S.CheckParamEnd(6)
115  )
116  {
117  return 0;
118  }
119 
120  // Read the params:
121  AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
122  S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
123 
124  // Add the rank:
125  cRoot::Get()->GetRankManager()->AddRank(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
126  return 0;
127 }
128 
129 
130 
131 
132 
135 {
136  // Function signature:
137  // cRankManager:AddRestrictionToGroup(Restriction, GroupName) -> bool
138 
139  cLuaState S(L);
140  if (
141  !S.CheckParamUserTable(1, "cRankManager") ||
142  !S.CheckParamString(2, 3) ||
143  !S.CheckParamEnd(4)
144  )
145  {
146  return 0;
147  }
148 
149  // Read the params:
150  AString GroupName, Restriction;
151  S.GetStackValues(2, Restriction, GroupName);
152 
153  // Add the group to the rank:
154  S.Push(cRoot::Get()->GetRankManager()->AddRestrictionToGroup(Restriction, GroupName));
155  return 1;
156 }
157 
158 
159 
160 
161 
163 static int tolua_cRankManager_ClearPlayerRanks(lua_State * L)
164 {
165  cLuaState S(L);
166  if (
167  !S.CheckParamUserTable(1, "cRankManager") ||
168  !S.CheckParamEnd(2)
169  )
170  {
171  return 0;
172  }
173 
174  // Remove all players:
176  return 1;
177 }
178 
179 
180 
181 
182 
184 static int tolua_cRankManager_GetAllGroups(lua_State * L)
185 {
186  // Function signature:
187  // cRankManager:GetAllGroups() -> arraytable of GroupNames
188 
189  cLuaState S(L);
190  if (
191  !S.CheckParamUserTable(1, "cRankManager") ||
192  !S.CheckParamEnd(2)
193  )
194  {
195  return 0;
196  }
197 
198  // Get the groups:
200 
201  // Push the results:
202  S.Push(Groups);
203  return 1;
204 }
205 
206 
207 
208 
209 
211 static int tolua_cRankManager_GetAllPermissions(lua_State * L)
212 {
213  // Function signature:
214  // cRankManager:GetAllPermissions() -> arraytable of Permissions
215 
216  cLuaState S(L);
217  if (
218  !S.CheckParamUserTable(1, "cRankManager") ||
219  !S.CheckParamEnd(2)
220  )
221  {
222  return 0;
223  }
224 
225  // Get the permissions:
227 
228  // Push the results:
229  S.Push(Permissions);
230  return 1;
231 }
232 
233 
234 
235 
236 
239 {
240  // Function signature:
241  // cRankManager:GetAllPermissionsRestrictions() -> arraytable of Permissions and Restrictions together
242 
243  cLuaState S(L);
244  if (
245  !S.CheckParamUserTable(1, "cRankManager") ||
246  !S.CheckParamEnd(2)
247  )
248  {
249  return 0;
250  }
251 
252  // Push the results:
253  S.Push(cRoot::Get()->GetRankManager()->GetAllPermissionsRestrictions());
254 
255  return 1;
256 }
257 
258 
259 
260 
261 
263 static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L)
264 {
265  // Function signature:
266  // cRankManager:GetAllPlayerUUIDs() -> arraytable of Player UUID's
267 
268  cLuaState S(L);
269  if (
270  !S.CheckParamStaticSelf("cRankManager") ||
271  !S.CheckParamEnd(2)
272  )
273  {
274  return 0;
275  }
276 
277  // Get the player uuid's:
278  std::vector<cUUID> Players = cRoot::Get()->GetRankManager()->GetAllPlayerUUIDs();
279 
280  // Convert to string UUIDs
281  std::vector<AString> StrUUIDs;
282  StrUUIDs.reserve(Players.size());
283  for (const auto & UUID : Players)
284  {
285  StrUUIDs.push_back(UUID.ToShortString());
286  }
287 
288  // Push the results:
289  S.Push(StrUUIDs);
290  return 1;
291 }
292 
293 
294 
295 
296 
298 static int tolua_cRankManager_GetAllRanks(lua_State * L)
299 {
300  // Function signature:
301  // cRankManager:GetAllRanks() -> arraytable of RankNames
302 
303  cLuaState S(L);
304  if (
305  !S.CheckParamUserTable(1, "cRankManager") ||
306  !S.CheckParamEnd(2)
307  )
308  {
309  return 0;
310  }
311 
312  // Push the results:
313  S.Push(cRoot::Get()->GetRankManager()->GetAllRanks());
314  return 1;
315 }
316 
317 
318 
319 
320 
322 static int tolua_cRankManager_GetAllRestrictions(lua_State * L)
323 {
324  // Function signature:
325  // cRankManager:GetAllRestrictions() -> arraytable of Restrictions
326 
327  cLuaState S(L);
328  if (
329  !S.CheckParamUserTable(1, "cRankManager") ||
330  !S.CheckParamEnd(2)
331  )
332  {
333  return 0;
334  }
335 
336  // Push the results:
337  S.Push(cRoot::Get()->GetRankManager()->GetAllRestrictions());
338 
339  return 1;
340 }
341 
342 
343 
344 
345 
347 static int tolua_cRankManager_GetDefaultRank(lua_State * L)
348 {
349  // Function signature:
350  // cRankManager:GetDefaultRank() -> string
351 
352  cLuaState S(L);
353  if (
354  !S.CheckParamUserTable(1, "cRankManager") ||
355  !S.CheckParamEnd(2)
356  )
357  {
358  return 0;
359  }
360 
361  // Return the rank name:
362  S.Push(cRoot::Get()->GetRankManager()->GetDefaultRank());
363  return 1;
364 }
365 
366 
367 
368 
369 
371 static int tolua_cRankManager_GetGroupPermissions(lua_State * L)
372 {
373  // Function signature:
374  // cRankManager:GetGroupPermissions(GroupName) -> arraytable of permissions
375 
376  cLuaState S(L);
377  if (
378  !S.CheckParamUserTable(1, "cRankManager") ||
379  !S.CheckParamString(2) ||
380  !S.CheckParamEnd(3)
381  )
382  {
383  return 0;
384  }
385 
386  // Get the params:
387  AString GroupName;
388  S.GetStackValue(2, GroupName);
389 
390  // Get the permissions:
391  AStringVector Permissions = cRoot::Get()->GetRankManager()->GetGroupPermissions(GroupName);
392 
393  // Push the results:
394  S.Push(Permissions);
395  return 1;
396 }
397 
398 
399 
400 
401 
404 {
405  // Function signature:
406  // cRankManager:GetGroupRestrictions(GroupName) -> arraytable of restrictions
407 
408  cLuaState S(L);
409  if (
410  !S.CheckParamUserTable(1, "cRankManager") ||
411  !S.CheckParamString(2) ||
412  !S.CheckParamEnd(3)
413  )
414  {
415  return 0;
416  }
417 
418  // Get the params:
419  AString GroupName;
420  S.GetStackValue(2, GroupName);
421 
422  // Get the restrictions:
423  AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetGroupRestrictions(GroupName);
424 
425  // Push the results:
426  S.Push(Restrictions);
427  return 1;
428 }
429 
430 
431 
432 
433 
435 static int tolua_cRankManager_GetPlayerGroups(lua_State * L)
436 {
437  // Function signature:
438  // cRankManager:GetPlayerGroups(PlayerUUID) -> arraytable of GroupNames
439 
440  cLuaState S(L);
441  if (
442  !S.CheckParamStaticSelf("cRankManager") ||
443  !S.CheckParamUUID(2) ||
444  !S.CheckParamEnd(3)
445  )
446  {
447  return 0;
448  }
449 
450  // Get the params:
451  cUUID PlayerUUID;
452  S.GetStackValue(2, PlayerUUID);
453 
454  // Get the groups:
455  AStringVector Groups = cRoot::Get()->GetRankManager()->GetPlayerGroups(PlayerUUID);
456 
457  // Push the results:
458  S.Push(Groups);
459  return 1;
460 }
461 
462 
463 
464 
465 
467 static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
468 {
469  // Function signature:
470  // cRankManager:GetPlayerMsgVisuals(PlayerUUID) -> string, string, string
471 
472  cLuaState S(L);
473  if (
474  !S.CheckParamStaticSelf("cRankManager") ||
475  !S.CheckParamUUID(2) ||
476  !S.CheckParamEnd(3)
477  )
478  {
479  return 0;
480  }
481 
482  // Get the params:
483  cUUID PlayerUUID;
484  S.GetStackValue(2, PlayerUUID);
485 
486  // Get the permissions:
487  AString MsgPrefix, MsgSuffix, MsgNameColorCode;
488  if (!cRoot::Get()->GetRankManager()->GetPlayerMsgVisuals(PlayerUUID, MsgPrefix, MsgSuffix, MsgNameColorCode))
489  {
490  return 0;
491  }
492 
493  // Push the results:
494  S.Push(MsgPrefix, MsgSuffix, MsgNameColorCode);
495  return 3;
496 }
497 
498 
499 
500 
501 
504 {
505  // Function signature:
506  // cRankManager:GetPlayerPermissions(PlayerUUID) -> arraytable of permissions
507 
508  cLuaState S(L);
509  if (
510  !S.CheckParamStaticSelf("cRankManager") ||
511  !S.CheckParamUUID(2) ||
512  !S.CheckParamEnd(3)
513  )
514  {
515  return 0;
516  }
517 
518  // Get the params:
519  cUUID PlayerUUID;
520  S.GetStackValue(2, PlayerUUID);
521 
522  // Get the permissions:
523  AStringVector Permissions = cRoot::Get()->GetRankManager()->GetPlayerPermissions(PlayerUUID);
524 
525  // Push the results:
526  S.Push(Permissions);
527  return 1;
528 }
529 
530 
531 
532 
533 
536 {
537  // Function signature:
538  // cRankManager:GetPlayerRestrictions(PlayerUUID) -> arraytable of restrictions
539 
540  cLuaState S(L);
541  if (
542  !S.CheckParamStaticSelf("cRankManager") ||
543  !S.CheckParamUUID(2) ||
544  !S.CheckParamEnd(3)
545  )
546  {
547  return 0;
548  }
549 
550  // Get the params:
551  cUUID PlayerUUID;
552  S.GetStackValue(2, PlayerUUID);
553 
554  // Get the permissions:
555  AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetPlayerRestrictions(PlayerUUID);
556 
557  // Push the results:
558  S.Push(Restrictions);
559  return 1;
560 }
561 
562 
563 
564 
565 
567 static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
568 {
569  // Function signature:
570  // cRankManager:GetPlayerRankName(PlayerUUID) -> string
571 
572  cLuaState S(L);
573  if (
574  !S.CheckParamStaticSelf("cRankManager") ||
575  !S.CheckParamUUID(2) ||
576  !S.CheckParamEnd(3)
577  )
578  {
579  return 0;
580  }
581 
582  // Get the params:
583  cUUID PlayerUUID;
584  S.GetStackValue(2, PlayerUUID);
585 
586  // Get the rank name:
587  AString RankName = cRoot::Get()->GetRankManager()->GetPlayerRankName(PlayerUUID);
588 
589  // Push the result:
590  S.Push(RankName);
591  return 1;
592 }
593 
594 
595 
596 
597 
599 static int tolua_cRankManager_GetPlayerName(lua_State * L)
600 {
601  // Function signature:
602  // cRankManager:GetPlayerName(PlayerUUID) -> string
603 
604  cLuaState S(L);
605  if (
606  !S.CheckParamStaticSelf("cRankManager") ||
607  !S.CheckParamUUID(2) ||
608  !S.CheckParamEnd(3)
609  )
610  {
611  return 0;
612  }
613 
614  // Get the params:
615  cUUID PlayerUUID;
616  S.GetStackValue(2, PlayerUUID);
617 
618  // Get the player name:
619  AString PlayerName = cRoot::Get()->GetRankManager()->GetPlayerName(PlayerUUID);
620 
621  // Push the result:
622  S.Push(PlayerName);
623  return 1;
624 }
625 
626 
627 
628 
629 
631 static int tolua_cRankManager_GetRankGroups(lua_State * L)
632 {
633  // Function signature:
634  // cRankManager:GetRankGroups(RankName) -> arraytable of groupnames
635 
636  cLuaState S(L);
637  if (
638  !S.CheckParamUserTable(1, "cRankManager") ||
639  !S.CheckParamString(2) ||
640  !S.CheckParamEnd(3)
641  )
642  {
643  return 0;
644  }
645 
646  // Get the params:
647  AString RankName;
648  S.GetStackValue(2, RankName);
649 
650  // Get the groups:
651  AStringVector Groups = cRoot::Get()->GetRankManager()->GetRankGroups(RankName);
652 
653  // Push the results:
654  S.Push(Groups);
655  return 1;
656 }
657 
658 
659 
660 
661 
663 static int tolua_cRankManager_GetRankPermissions(lua_State * L)
664 {
665  // Function signature:
666  // cRankManager:GetRankPermissions(RankName) -> arraytable of permissions
667 
668  cLuaState S(L);
669  if (
670  !S.CheckParamUserTable(1, "cRankManager") ||
671  !S.CheckParamString(2) ||
672  !S.CheckParamEnd(3)
673  )
674  {
675  return 0;
676  }
677 
678  // Get the params:
679  AString RankName;
680  S.GetStackValue(2, RankName);
681 
682  // Get the permissions:
683  AStringVector Permissions = cRoot::Get()->GetRankManager()->GetRankPermissions(RankName);
684 
685  // Push the results:
686  S.Push(Permissions);
687  return 1;
688 }
689 
690 
691 
692 
693 
695 static int tolua_cRankManager_GetRankRestrictions(lua_State * L)
696 {
697  // Function signature:
698  // cRankManager:GetRankRestrictions(RankName) -> arraytable of restrictions
699 
700  cLuaState S(L);
701  if (
702  !S.CheckParamUserTable(1, "cRankManager") ||
703  !S.CheckParamString(2) ||
704  !S.CheckParamEnd(3)
705  )
706  {
707  return 0;
708  }
709 
710  // Get the params:
711  AString RankName;
712  S.GetStackValue(2, RankName);
713 
714  // Get the permissions:
715  AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetRankRestrictions(RankName);
716 
717  // Push the results:
718  S.Push(Restrictions);
719  return 1;
720 }
721 
722 
723 
724 
725 
727 static int tolua_cRankManager_GetRankVisuals(lua_State * L)
728 {
729  // Function signature:
730  // cRankManager:GetRankVisuals(RankName) -> MsgPrefix, MsgSuffix, MsgNameColorCode
731 
732  cLuaState S(L);
733  if (
734  !S.CheckParamUserTable(1, "cRankManager") ||
735  !S.CheckParamString(2) ||
736  !S.CheckParamEnd(3)
737  )
738  {
739  return 0;
740  }
741 
742  // Get the params:
743  AString RankName;
744  S.GetStackValue(2, RankName);
745 
746  // Get the visuals:
747  AString MsgPrefix, MsgSuffix, MsgNameColorCode;
748  if (!cRoot::Get()->GetRankManager()->GetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode))
749  {
750  // No such rank, return nothing:
751  return 0;
752  }
753 
754  // Push the results:
755  S.Push(MsgPrefix, MsgSuffix, MsgNameColorCode);
756  return 3;
757 }
758 
759 
760 
761 
762 
764 static int tolua_cRankManager_GroupExists(lua_State * L)
765 {
766  // Function signature:
767  // cRankManager:GroupExists(GroupName) -> bool
768 
769  cLuaState S(L);
770  if (
771  !S.CheckParamUserTable(1, "cRankManager") ||
772  !S.CheckParamString(2) ||
773  !S.CheckParamEnd(3)
774  )
775  {
776  return 0;
777  }
778 
779  // Get the params:
780  AString GroupName;
781  S.GetStackValue(2, GroupName);
782 
783  // Get the response:
784  bool res = cRoot::Get()->GetRankManager()->GroupExists(GroupName);
785 
786  // Push the result:
787  S.Push(res);
788  return 1;
789 }
790 
791 
792 
793 
794 
796 static int tolua_cRankManager_IsGroupInRank(lua_State * L)
797 {
798  // Function signature:
799  // cRankManager:IsGroupInRank(GroupName, RankName) -> bool
800 
801  cLuaState S(L);
802  if (
803  !S.CheckParamUserTable(1, "cRankManager") ||
804  !S.CheckParamString(2, 3) ||
805  !S.CheckParamEnd(4)
806  )
807  {
808  return 0;
809  }
810 
811  // Get the params:
812  AString GroupName, RankName;
813  S.GetStackValues(2, GroupName, RankName);
814 
815  // Get the response:
816  bool res = cRoot::Get()->GetRankManager()->IsGroupInRank(GroupName, RankName);
817 
818  // Push the result:
819  S.Push(res);
820  return 1;
821 }
822 
823 
824 
825 
826 
828 static int tolua_cRankManager_IsPermissionInGroup(lua_State * L)
829 {
830  // Function signature:
831  // cRankManager:IsPermissionInGroup(Permission, GroupName) -> bool
832 
833  cLuaState S(L);
834  if (
835  !S.CheckParamUserTable(1, "cRankManager") ||
836  !S.CheckParamString(2, 3) ||
837  !S.CheckParamEnd(4)
838  )
839  {
840  return 0;
841  }
842 
843  // Get the params:
844  AString GroupName, Permission;
845  S.GetStackValues(2, Permission, GroupName);
846 
847  // Get the response:
848  bool res = cRoot::Get()->GetRankManager()->IsPermissionInGroup(Permission, GroupName);
849 
850  // Push the result:
851  S.Push(res);
852  return 1;
853 }
854 
855 
856 
857 
858 
861 {
862  // Function signature:
863  // cRankManager:IsRestrictionInGroup(Restriction, GroupName) -> bool
864 
865  cLuaState S(L);
866  if (
867  !S.CheckParamUserTable(1, "cRankManager") ||
868  !S.CheckParamString(2, 3) ||
869  !S.CheckParamEnd(4)
870  )
871  {
872  return 0;
873  }
874 
875  // Get the params:
876  AString GroupName, Restriction;
877  S.GetStackValues(2, Restriction, GroupName);
878 
879  // Get the response:
880  bool res = cRoot::Get()->GetRankManager()->IsRestrictionInGroup(Restriction, GroupName);
881 
882  // Push the result:
883  S.Push(res);
884  return 1;
885 }
886 
887 
888 
889 
890 
892 static int tolua_cRankManager_IsPlayerRankSet(lua_State * L)
893 {
894  // Function signature:
895  // cRankManager:IsPlayerRankSet(PlayerUUID) -> bool
896 
897  cLuaState S(L);
898  if (
899  !S.CheckParamStaticSelf("cRankManager") ||
900  !S.CheckParamUUID(2) ||
901  !S.CheckParamEnd(3)
902  )
903  {
904  return 0;
905  }
906 
907  // Get the params:
908  cUUID PlayerUUID;
909  S.GetStackValue(2, PlayerUUID);
910 
911  // Get the response:
912  bool res = cRoot::Get()->GetRankManager()->IsPlayerRankSet(PlayerUUID);
913 
914  // Push the result:
915  S.Push(res);
916  return 1;
917 }
918 
919 
920 
921 
922 
924 static int tolua_cRankManager_RankExists(lua_State * L)
925 {
926  // Function signature:
927  // cRankManager:RankExists(RankName) -> bool
928 
929  cLuaState S(L);
930  if (
931  !S.CheckParamUserTable(1, "cRankManager") ||
932  !S.CheckParamString(2) ||
933  !S.CheckParamEnd(3)
934  )
935  {
936  return 0;
937  }
938 
939  // Get the params:
940  AString RankName;
941  S.GetStackValue(2, RankName);
942 
943  // Get the response:
944  bool res = cRoot::Get()->GetRankManager()->RankExists(RankName);
945 
946  // Push the result:
947  S.Push(res);
948  return 1;
949 }
950 
951 
952 
953 
954 
956 static int tolua_cRankManager_RemoveGroup(lua_State * L)
957 {
958  // Function signature:
959  // cRankManager:RemoveGroup(GroupName)
960 
961  cLuaState S(L);
962  if (
963  !S.CheckParamUserTable(1, "cRankManager") ||
964  !S.CheckParamString(2) ||
965  !S.CheckParamEnd(3)
966  )
967  {
968  return 0;
969  }
970 
971  // Get the params:
972  AString GroupName;
973  S.GetStackValue(2, GroupName);
974 
975  // Remove the group:
976  cRoot::Get()->GetRankManager()->RemoveGroup(GroupName);
977  return 0;
978 }
979 
980 
981 
982 
983 
985 static int tolua_cRankManager_RemoveGroupFromRank(lua_State * L)
986 {
987  // Function signature:
988  // cRankManager:RemoveGroupFromRank(GroupName, RankName)
989 
990  cLuaState S(L);
991  if (
992  !S.CheckParamUserTable(1, "cRankManager") ||
993  !S.CheckParamString(2, 3) ||
994  !S.CheckParamEnd(4)
995  )
996  {
997  return 0;
998  }
999 
1000  // Get the params:
1001  AString GroupName, RankName;
1002  S.GetStackValues(2, GroupName, RankName);
1003 
1004  // Remove the group:
1005  cRoot::Get()->GetRankManager()->RemoveGroupFromRank(GroupName, RankName);
1006  return 0;
1007 }
1008 
1009 
1010 
1011 
1012 
1015 {
1016  // Function signature:
1017  // cRankManager:RemovePermissionFromGroup(Permission, GroupName)
1018 
1019  cLuaState S(L);
1020  if (
1021  !S.CheckParamUserTable(1, "cRankManager") ||
1022  !S.CheckParamString(2, 3) ||
1023  !S.CheckParamEnd(4)
1024  )
1025  {
1026  return 0;
1027  }
1028 
1029  // Get the params:
1030  AString GroupName, Permission;
1031  S.GetStackValues(2, Permission, GroupName);
1032 
1033  // Remove the permission:
1034  cRoot::Get()->GetRankManager()->RemovePermissionFromGroup(Permission, GroupName);
1035  return 0;
1036 }
1037 
1038 
1039 
1040 
1041 
1044 {
1045  // Function signature:
1046  // cRankManager:RemoveRestrictionFromGroup(Restriction, GroupName)
1047 
1048  cLuaState S(L);
1049  if (
1050  !S.CheckParamUserTable(1, "cRankManager") ||
1051  !S.CheckParamString(2, 3) ||
1052  !S.CheckParamEnd(4)
1053  )
1054  {
1055  return 0;
1056  }
1057 
1058  // Get the params:
1059  AString GroupName, Restriction;
1060  S.GetStackValues(2, Restriction, GroupName);
1061 
1062  // Remove the restriction:
1063  cRoot::Get()->GetRankManager()->RemoveRestrictionFromGroup(Restriction, GroupName);
1064  return 0;
1065 }
1066 
1067 
1068 
1069 
1070 
1072 static int tolua_cRankManager_RemovePlayerRank(lua_State * L)
1073 {
1074  // Function signature:
1075  // cRankManager:RemovePlayerRank(PlayerUUID)
1076 
1077  cLuaState S(L);
1078  if (
1079  !S.CheckParamStaticSelf("cRankManager") ||
1080  !S.CheckParamUUID(2) ||
1081  !S.CheckParamEnd(3)
1082  )
1083  {
1084  return 0;
1085  }
1086 
1087  // Get the params:
1088  cUUID PlayerUUID;
1089  S.GetStackValue(2, PlayerUUID);
1090 
1091  // Remove the player's rank:
1092  cRoot::Get()->GetRankManager()->RemovePlayerRank(PlayerUUID);
1093  return 0;
1094 }
1095 
1096 
1097 
1098 
1099 
1101 static int tolua_cRankManager_RemoveRank(lua_State * L)
1102 {
1103  // Function signature:
1104  // cRankManager:RemoveRank(RankName, [ReplacementRankName])
1105 
1106  cLuaState S(L);
1107  if (
1108  !S.CheckParamUserTable(1, "cRankManager") ||
1109  !S.CheckParamString(2) ||
1110  // Param 3 is otpional, defaults to nil -> empty string
1111  !S.CheckParamEnd(4)
1112  )
1113  {
1114  return 0;
1115  }
1116 
1117  // Get the params:
1118  AString RankName, ReplacementRankName;
1119  S.GetStackValues(2, RankName, ReplacementRankName);
1120 
1121  // Remove the rank:
1122  cRoot::Get()->GetRankManager()->RemoveRank(RankName, ReplacementRankName);
1123  return 0;
1124 }
1125 
1126 
1127 
1128 
1129 
1131 static int tolua_cRankManager_RenameGroup(lua_State * L)
1132 {
1133  // Function signature:
1134  // cRankManager:RenameGroup(OldName, NewName)
1135 
1136  cLuaState S(L);
1137  if (
1138  !S.CheckParamUserTable(1, "cRankManager") ||
1139  !S.CheckParamString(2, 3) ||
1140  !S.CheckParamEnd(4)
1141  )
1142  {
1143  return 0;
1144  }
1145 
1146  // Get the params:
1147  AString OldName, NewName;
1148  S.GetStackValues(2, OldName, NewName);
1149 
1150  // Remove the group:
1151  bool res = cRoot::Get()->GetRankManager()->RenameGroup(OldName, NewName);
1152 
1153  // Push the result:
1154  S.Push(res);
1155  return 1;
1156 }
1157 
1158 
1159 
1160 
1161 
1163 static int tolua_cRankManager_RenameRank(lua_State * L)
1164 {
1165  // Function signature:
1166  // cRankManager:RenameRank(OldName, NewName)
1167 
1168  cLuaState S(L);
1169  if (
1170  !S.CheckParamUserTable(1, "cRankManager") ||
1171  !S.CheckParamString(2, 3) ||
1172  !S.CheckParamEnd(4)
1173  )
1174  {
1175  return 0;
1176  }
1177 
1178  // Get the params:
1179  AString OldName, NewName;
1180  S.GetStackValues(2, OldName, NewName);
1181 
1182  // Remove the rank:
1183  bool res = cRoot::Get()->GetRankManager()->RenameRank(OldName, NewName);
1184 
1185  // Push the result:
1186  S.Push(res);
1187  return 1;
1188 }
1189 
1190 
1191 
1192 
1193 
1195 static int tolua_cRankManager_SetDefaultRank(lua_State * L)
1196 {
1197  // Function signature:
1198  // cRankManager:SetDefaultRank(RankName) -> bool
1199 
1200  cLuaState S(L);
1201  if (
1202  !S.CheckParamUserTable(1, "cRankManager") ||
1203  !S.CheckParamString(2) ||
1204  !S.CheckParamEnd(3)
1205  )
1206  {
1207  return 0;
1208  }
1209 
1210  // Get the params:
1211  AString RankName;
1212  S.GetStackValue(2, RankName);
1213 
1214  // Set the rank, return the result:
1215  S.Push(cRoot::Get()->GetRankManager()->SetDefaultRank(RankName));
1216  return 1;
1217 }
1218 
1219 
1220 
1221 
1222 
1224 static int tolua_cRankManager_SetPlayerRank(lua_State * L)
1225 {
1226  // Function signature:
1227  // cRankManager:SetPlayerRank(PlayerUUID, PlayerName, RankName)
1228 
1229  cLuaState S(L);
1230  if (
1231  !S.CheckParamStaticSelf("cRankManager") ||
1232  !S.CheckParamUUID(2) ||
1233  !S.CheckParamString(3, 4) ||
1234  !S.CheckParamEnd(5)
1235  )
1236  {
1237  return 0;
1238  }
1239 
1240  // Get the params:
1241  AString PlayerName, RankName;
1242  cUUID PlayerUUID;
1243  S.GetStackValues(2, PlayerUUID, PlayerName, RankName);
1244 
1245  // Set the rank:
1246  cRoot::Get()->GetRankManager()->SetPlayerRank(PlayerUUID, PlayerName, RankName);
1247  return 0;
1248 }
1249 
1250 
1251 
1252 
1253 
1255 static int tolua_cRankManager_SetRankVisuals(lua_State * L)
1256 {
1257  // Function signature:
1258  // cRankManager:SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode)
1259 
1260  cLuaState S(L);
1261  if (
1262  !S.CheckParamUserTable(1, "cRankManager") ||
1263  !S.CheckParamString(2, 5) ||
1264  !S.CheckParamEnd(6)
1265  )
1266  {
1267  return 0;
1268  }
1269 
1270  // Get the params:
1271  AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
1272  S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
1273 
1274  // Set the visuals:
1275  cRoot::Get()->GetRankManager()->SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
1276  return 0;
1277 }
1278 
1279 
1280 
1281 
1282 
1283 void cManualBindings::BindRankManager(lua_State * tolua_S)
1284 {
1285  // Create the cRankManager class in the API:
1286  tolua_usertype(tolua_S, "cRankManager");
1287  tolua_cclass(tolua_S, "cRankManager", "cRankManager", "", nullptr);
1288 
1289  // Fill in the functions (alpha-sorted):
1290  tolua_beginmodule(tolua_S, "cRankManager");
1291  tolua_function(tolua_S, "AddGroup", tolua_cRankManager_AddGroup);
1292  tolua_function(tolua_S, "AddGroupToRank", tolua_cRankManager_AddGroupToRank);
1293  tolua_function(tolua_S, "AddPermissionToGroup", tolua_cRankManager_AddPermissionToGroup);
1294  tolua_function(tolua_S, "AddRestrictionToGroup", tolua_cRankManager_AddRestrictionToGroup);
1295  tolua_function(tolua_S, "AddRank", tolua_cRankManager_AddRank);
1296  tolua_function(tolua_S, "ClearPlayerRanks", tolua_cRankManager_ClearPlayerRanks);
1297  tolua_function(tolua_S, "GetAllGroups", tolua_cRankManager_GetAllGroups);
1298  tolua_function(tolua_S, "GetAllPermissions", tolua_cRankManager_GetAllPermissions);
1299  tolua_function(tolua_S, "GetAllRestrictions", tolua_cRankManager_GetAllRestrictions);
1300  tolua_function(tolua_S, "GetAllPermissionsRestrictions", tolua_cRankManager_GetAllPermissionsRestrictions);
1301  tolua_function(tolua_S, "GetAllPlayerUUIDs", tolua_cRankManager_GetAllPlayerUUIDs);
1302  tolua_function(tolua_S, "GetAllRanks", tolua_cRankManager_GetAllRanks);
1303  tolua_function(tolua_S, "GetDefaultRank", tolua_cRankManager_GetDefaultRank);
1304  tolua_function(tolua_S, "GetGroupPermissions", tolua_cRankManager_GetGroupPermissions);
1305  tolua_function(tolua_S, "GetGroupRestrictions", tolua_cRankManager_GetGroupRestrictions);
1306  tolua_function(tolua_S, "GetPlayerGroups", tolua_cRankManager_GetPlayerGroups);
1307  tolua_function(tolua_S, "GetPlayerMsgVisuals", tolua_cRankManager_GetPlayerMsgVisuals);
1308  tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
1309  tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerRestrictions);
1310  tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
1311  tolua_function(tolua_S, "GetPlayerName", tolua_cRankManager_GetPlayerName);
1312  tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
1313  tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
1314  tolua_function(tolua_S, "GetRankRestrictions", tolua_cRankManager_GetRankRestrictions);
1315  tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals);
1316  tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists);
1317  tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank);
1318  tolua_function(tolua_S, "IsPermissionInGroup", tolua_cRankManager_IsPermissionInGroup);
1319  tolua_function(tolua_S, "IsRestrictionInGroup", tolua_cRankManager_IsRestrictionInGroup);
1320  tolua_function(tolua_S, "IsPlayerRankSet", tolua_cRankManager_IsPlayerRankSet);
1321  tolua_function(tolua_S, "RankExists", tolua_cRankManager_RankExists);
1322  tolua_function(tolua_S, "RemoveGroup", tolua_cRankManager_RemoveGroup);
1323  tolua_function(tolua_S, "RemoveGroupFromRank", tolua_cRankManager_RemoveGroupFromRank);
1324  tolua_function(tolua_S, "RemovePermissionFromGroup", tolua_cRankManager_RemovePermissionFromGroup);
1325  tolua_function(tolua_S, "RemoveRestrictionFromGroup", tolua_cRankManager_RemoveRestrictionFromGroup);
1326  tolua_function(tolua_S, "RemovePlayerRank", tolua_cRankManager_RemovePlayerRank);
1327  tolua_function(tolua_S, "RemoveRank", tolua_cRankManager_RemoveRank);
1328  tolua_function(tolua_S, "RenameGroup", tolua_cRankManager_RenameGroup);
1329  tolua_function(tolua_S, "RenameRank", tolua_cRankManager_RenameRank);
1330  tolua_function(tolua_S, "SetDefaultRank", tolua_cRankManager_SetDefaultRank);
1331  tolua_function(tolua_S, "SetPlayerRank", tolua_cRankManager_SetPlayerRank);
1332  tolua_function(tolua_S, "SetRankVisuals", tolua_cRankManager_SetRankVisuals);
1333  tolua_endmodule(tolua_S);
1334 }
1335 
1336 
1337 
1338 
static int tolua_cRankManager_RemoveGroupFromRank(lua_State *L)
Binds cRankManager::RemoveGroupFromRank.
static int tolua_cRankManager_SetDefaultRank(lua_State *L)
Binds cRankManager::SetDefaultRank.
static int tolua_cRankManager_AddRestrictionToGroup(lua_State *L)
Binds cRankManager::AddRestrictionToGroup.
static int tolua_cRankManager_GetRankRestrictions(lua_State *L)
Binds cRankManager::GetRankRestrictions.
static int tolua_cRankManager_AddGroupToRank(lua_State *L)
Binds cRankManager::AddGroupToRank.
static int tolua_cRankManager_GetGroupPermissions(lua_State *L)
Binds cRankManager::GetGroupPermissions.
static int tolua_cRankManager_SetRankVisuals(lua_State *L)
Binds cRankManager::SetRankVisuals.
static int tolua_cRankManager_RemoveGroup(lua_State *L)
Binds cRankManager::RemoveGroup.
static int tolua_cRankManager_AddGroup(lua_State *L)
Binds cRankManager::AddGroup.
static int tolua_cRankManager_GetAllRanks(lua_State *L)
Binds cRankManager::GetAllRanks.
static int tolua_cRankManager_RemoveRestrictionFromGroup(lua_State *L)
Binds cRankManager::RemoveRestrictionFromGroup.
static int tolua_cRankManager_IsPlayerRankSet(lua_State *L)
Binds cRankManager::IsPlayerRankSet.
static int tolua_cRankManager_RemoveRank(lua_State *L)
Binds cRankManager::RemoveRank.
static int tolua_cRankManager_GetRankPermissions(lua_State *L)
Binds cRankManager::GetRankPermissions.
static int tolua_cRankManager_AddRank(lua_State *L)
Binds cRankManager::AddRank.
static int tolua_cRankManager_IsRestrictionInGroup(lua_State *L)
Binds cRankManager::IsRestrictionInGroup.
static int tolua_cRankManager_GetPlayerName(lua_State *L)
Binds cRankManager::GetPlayerName.
static int tolua_cRankManager_GetPlayerRestrictions(lua_State *L)
Binds cRankManager::GetPlayerRestrictions.
static int tolua_cRankManager_RemovePlayerRank(lua_State *L)
Binds cRankManager::RemovePlayerRank.
static int tolua_cRankManager_SetPlayerRank(lua_State *L)
Binds cRankManager::SetPlayerRank.
static int tolua_cRankManager_GetPlayerRankName(lua_State *L)
Binds cRankManager::GetPlayerRankName.
static int tolua_cRankManager_RemovePermissionFromGroup(lua_State *L)
Binds cRankManager::RemovePermissionFromGroup.
static int tolua_cRankManager_AddPermissionToGroup(lua_State *L)
Binds cRankManager::AddPermissionToGroup.
static int tolua_cRankManager_GetRankVisuals(lua_State *L)
Binds cRankManager::GetRankVisuals.
static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State *L)
Binds cRankManager::GetPlayerMsgVisuals.
static int tolua_cRankManager_GetAllPermissions(lua_State *L)
Binds cRankManager::GetAllPermissions.
static int tolua_cRankManager_GetDefaultRank(lua_State *L)
Binds cRankManager::GetDefaultRank.
static int tolua_cRankManager_GetAllGroups(lua_State *L)
Binds cRankManager::GetAllGroups.
static int tolua_cRankManager_IsGroupInRank(lua_State *L)
Binds cRankManager::IsGroupInRank.
static int tolua_cRankManager_IsPermissionInGroup(lua_State *L)
Binds cRankManager::IsPermissionInGroup.
static int tolua_cRankManager_RenameRank(lua_State *L)
Binds cRankManager::RenameRank.
static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State *L)
Binds cRankManager::GetAllPlayerUUIDs.
static int tolua_cRankManager_GetRankGroups(lua_State *L)
Binds cRankManager::GetRankGroups.
static int tolua_cRankManager_GroupExists(lua_State *L)
Binds cRankManager::GroupExists.
static int tolua_cRankManager_RenameGroup(lua_State *L)
Binds cRankManager::RenameGroup.
static int tolua_cRankManager_GetAllRestrictions(lua_State *L)
Binds cRankManager::GetAllRestrictions.
static int tolua_cRankManager_GetPlayerGroups(lua_State *L)
Binds cRankManager::GetPlayerGroups.
static int tolua_cRankManager_ClearPlayerRanks(lua_State *L)
Binds cRankManager::ClearPlayerRanks.
static int tolua_cRankManager_RankExists(lua_State *L)
Binds cRankManager::RankExists.
static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State *L)
Binds cRankManager::GetAllPermissionsRestrictions.
static int tolua_cRankManager_GetGroupRestrictions(lua_State *L)
Binds cRankManager::GetGroupRestrictions.
static int tolua_cRankManager_GetPlayerPermissions(lua_State *L)
Binds cRankManager::GetPlayerPermissions.
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
Encapsulates a Lua state and provides some syntactic sugar for common operations.
Definition: LuaState.h:56
void Push(Arg1 &&a_Arg1, Arg2 &&a_Arg2, Args &&... a_Args)
Pushes multiple arguments onto the Lua stack.
Definition: LuaState.h:604
bool CheckParamEnd(int a_Param)
Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters)
Definition: LuaState.cpp:1998
bool CheckParamString(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are strings; also logs warning if not.
Definition: LuaState.cpp:1829
bool CheckParamUserTable(int a_StartParam, const char *a_UserTable, int a_EndParam=-1)
Returns true if the specified parameters on the stack are of the specified usertable type; also logs ...
Definition: LuaState.cpp:1661
bool CheckParamUUID(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are UUIDs; also logs warning if not Accepts eit...
Definition: LuaState.cpp:1957
bool CheckParamStaticSelf(const char *a_SelfClassName)
Returns true if the first parameter is the expected class (static).
Definition: LuaState.cpp:2043
bool GetStackValue(int a_StackPos, AString &a_Value)
Definition: LuaState.cpp:1119
bool GetStackValues(int a_StartStackPos, Arg1 &&a_Arg1, Args &&... args)
Retrieves a list of values from the Lua stack, starting at the specified index.
Definition: LuaState.h:766
AStringVector GetGroupPermissions(const AString &a_GroupName)
Returns the permissions that the specified group has assigned to it.
void AddGroup(const AString &a_GroupName)
Adds a new permission group.
AStringVector GetGroupRestrictions(const AString &a_GroupName)
Returns the restrictions that the specified group has assigned to it.
bool IsPermissionInGroup(const AString &a_Permission, const AString &a_GroupName)
Returns true iff the specified group contains the specified permission.
void RemoveRestrictionFromGroup(const AString &a_Restriction, const AString &a_GroupName)
Removes the specified restriction from the specified group.
bool GroupExists(const AString &a_GroupName)
Returns true iff the specified group exists in the DB.
void SetRankVisuals(const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
Sets the message visuals of an existing rank.
bool RenameGroup(const AString &a_OldName, const AString &a_NewName)
Renames the specified group.
void RemovePlayerRank(const cUUID &a_PlayerUUID)
Removes the player's rank assignment.
AStringVector GetPlayerPermissions(const cUUID &a_PlayerUUID)
Returns the permissions that the specified player has assigned to them.
AStringVector GetAllGroups(void)
Returns the names of all permission groups.
void AddRank(const AString &a_RankName, const AString &a_MsgPrefix, const AString &a_MsgSuffix, const AString &a_MsgNameColorCode)
Adds a new rank.
bool RankExists(const AString &a_RankName)
Returns true iff the specified rank exists in the DB.
AStringVector GetRankPermissions(const AString &a_RankName)
Returns all permissions that the specified rank has assigned to it, through all its groups.
AString GetPlayerName(const cUUID &a_PlayerUUID)
Returns the last name that the specified player has.
bool IsPlayerRankSet(const cUUID &a_PlayerUUID)
Returns true iff the specified player has a rank assigned to them in the DB.
void RemovePermissionFromGroup(const AString &a_Permission, const AString &a_GroupName)
Removes the specified permission from the specified group.
AStringVector GetPlayerGroups(const cUUID &a_PlayerUUID)
Returns the names of Groups that the specified player has assigned to them.
AString GetPlayerRankName(const cUUID &a_PlayerUUID)
Returns the name of the rank that the specified player has assigned to them.
Definition: RankManager.cpp:90
void RemoveGroupFromRank(const AString &a_GroupName, const AString &a_RankName)
Removes the specified group from the specified rank.
AStringVector GetRankGroups(const AString &a_RankName)
Returns the names of groups that the specified rank has assigned to it.
void RemoveGroup(const AString &a_GroupName)
Removes the specified group completely.
void SetPlayerRank(const cUUID &a_PlayerUUID, const AString &a_PlayerName, const AString &a_RankName)
Sets the specified player's rank.
AStringVector GetRankRestrictions(const AString &a_RankName)
Returns all restrictions that the specified rank has assigned to it, through all its groups.
void RemoveRank(const AString &a_RankName, const AString &a_ReplacementRankName)
Removes the specified rank.
std::vector< cUUID > GetAllPlayerUUIDs(void)
Returns the uuids of all defined players.
AStringVector GetPlayerRestrictions(const cUUID &a_PlayerUUID)
Returns the restrictions that the specified player has assigned to them.
bool RenameRank(const AString &a_OldName, const AString &a_NewName)
Renames the specified rank.
AStringVector GetAllPermissions(void)
Returns all the distinct permissions that are stored in the DB.
void ClearPlayerRanks(void)
Removes all player ranks from the database.
bool IsGroupInRank(const AString &a_GroupName, const AString &a_RankName)
Returns true iff the specified rank contains the specified group.
bool IsRestrictionInGroup(const AString &a_Restriction, const AString &a_GroupName)
Returns true iff the specified group contains the specified restriction.
static cRoot * Get()
Definition: Root.h:52
cRankManager * GetRankManager(void)
Definition: Root.h:114
Definition: UUID.h:11